MVC3学习~
来源:互联网 发布:淘宝店标网站 编辑:程序博客网 时间:2024/06/04 20:11
路由设置:
/{controller}/{action}/{id},其中id是可选的
这样增加个修改参数:
/{controller}/{action}/{type}/{id},其中,type和id都是可选的。
1、@Html.ActionLink(item.Name, "Details", new { Id = item.Id }, new { @target = "_blank" })
item.Name:显示value值
Details:跳转到Details下
item.Id:跳转后传入的值Id
@target :跳转方式
2、@Url.Action("Details", new { Id = item.Id })
Details:跳转到的页面
item.Id:传入参数
如需传入多个参数值的话,@Url.Action("Details", new { Id1= item.Id1 },new { Id2 = item.Id2 })
3、两不同文件夹页面间跳转
@{Html.RenderAction("RankList", "Products");}
从当前文件夹的文件下跳转到Products文件夹下的RankList
若需要带参数则
@Html.ActionLink(item2.Name.CutString(15), "Details", "Articles", new { id = item2.Id }, null)
4、需对一个文本框进行限制字数
@Html.TextBoxFor(m => m.Name, new { @maxlength = "30" })
5、按钮事件写法
<input type="submit" name="login_submit" id="login_submit" value="" class="sub_static" />
public ActionResult LogOn()
{
return View();
}
//-----------------------这里注意,上面那个没有HttpPost,下面这个代表你点了以后回传到该事件
[HttpPost]
public virtual ActionResult LogOn(LogOnModel item)
{
bool isPower = false;
string ip = Request.UserHostAddress;
LogOn();//-------------注意,这里一定要写
if (!ModelState.IsValid)
{
return View(item);
}
var item1 = _UsersBLL.Get(item.Name);
if (item1 != null)
{
if (_UsersBLL.CheckUser(item1.Id, item.Password))
{
FormsAuthentication.SetAuthCookie(item1.Id.ToString(), item.RememberMe);
isPower = item1.IsPower.HasValue? (item1.IsPower.Value? true:false):false;
Logs log = new Logs { Id = Guid.NewGuid(), CreateTime = DateTime.Now, UserId = item1.Id, Name = "用户登录", Content = item1.Name + "用户登录成功", IP = ip };
_LogsBLL.Save(null, ref log);
if (isPower)
{
return Redirect("/Admin");
}
else
{
if (Request["ReturnUrl"] != null)
{
return Redirect(Request["ReturnUrl"]);
}
else
{
return Redirect("/");
}
}
}
else
{
Logs log = new Logs { Id = Guid.NewGuid(), CreateTime = DateTime.Now, UserId = null, Name = "用户登录", Content = "<span style='color:red'>失败的用户登录尝试。</span>", IP = ip };
_LogsBLL.Save(null, ref log);
ModelState.AddModelError("", "用户名不存在或密码错误!");
}
}
else
{
Logs log = new Logs { Id = Guid.NewGuid(), CreateTime = DateTime.Now, UserId = null, Name = "用户登录", Content = "<span style='color:red'>失败的用户登录尝试。</span>", IP = ip };
_LogsBLL.Save(null, ref log);
ModelState.AddModelError("", "用户名不存在或密码错误!");
}
return View(item);
}
- MVC3学习~
- MVC3 学习笔记1
- mvc3 学习 第一天
- MVC3学习笔记杂谈
- MVC3.0 中Razor 学习
- Asp.net MVC3学习案例
- MVC3+EF4.1学习系列
- MVC3.0 中Razor 学习
- MVC3.0 中Razor 学习
- mvc3 路由学习 自定义路由
- MVC3.0 中Razor 学习
- MVC3.0 中Razor 学习
- MVC3+EF4.1学习系列
- MVC3.0 中Razor 学习
- MVC3+EF4.1学习系列
- mvc3
- ASP.NET MVC3 及其学习资源
- ASP.NET MVC2, MVC3 & VS2010学习
- 2012-2013年度总结——思想篇
- notes of 《Inside the C++ object model》
- 从细节处窥探Vb
- 天勤OJ 题目1386: 围圈报数
- zoj 1813 Biker's Trip Odometer
- MVC3学习~
- 时间管理的感受篇
- 瑞雪兆丰年——与Vb的第一次相遇相知
- 你若安好,便是晴天
- css常用综合案例
- 考拉小巫与我
- Image显示服务器上任意绝对路径下的图片
- oracle 不可见索引
- Codeforces Round #167 (Div. 1)