首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

MVC3 点击页面的注册按钮没反应,调试Controller中的Register也没有调试到,该怎么解决

2012-05-30 
MVC3 点击页面的注册按钮没反应,调试Controller中的Register也没有调试到用MVC3实现的点击页面的注册按钮

MVC3 点击页面的注册按钮没反应,调试Controller中的Register也没有调试到
用MVC3实现的
点击页面的注册按钮没反应,调试Controller中的Register也没有调试到

HTML code
<div class="row">    @Html.LabelFor(model => model.Department)    @Html.EditorFor(model => model.Department)    @Html.ValidationMessageFor(model => model.Department)</div><div class="row">    @Html.LabelFor(model => model.Telephone)    @Html.EditorFor(model => model.Telephone)    @Html.ValidationMessageFor(model => model.Telephone)</div><div class="row">    @Html.LabelFor(model => model.Mobile)    @Html.EditorFor(model => model.Mobile)    @Html.ValidationMessageFor(model => model.Mobile)</div><div class="row">    @Html.LabelFor(model => model.Address)    @Html.EditorFor(model => model.Address)    @Html.ValidationMessageFor(model => model.Address)</div><div class="row">    @Html.LabelFor(model => model.Desc)    @Html.TextAreaFor(model => model.Desc)    @Html.ValidationMessageFor(model => model.Desc)    @Html.Hidden("Status",true)</div><div class="row">    <input type="submit" value="注册" />    <a href="javascript:history.go(-1)">返回</a>    @*@Html.ActionLink("返回", "Index")*@</div>


C# code
#region 注册用户        public ActionResult Register()        {            return View();        }        [HttpPost]        public ActionResult Register(FormCollection collection)        {            var user = new NalUser();            TryUpdateModel(user, collection);            if (ModelState.IsValid)            {                acc.AddUser(user);                acc.SaveChanges();            }            return RedirectToAction("Index");        }        #endregion

调试了可以看到,点击注册按钮,根本没跳到Controller里的Register方法。

[解决办法]
using (@Html.BeginForm("Register", "controller名字"))
{
<div class="row">
@Html.LabelFor(model => model.Department)
@Html.EditorFor(model => model.Department)
@Html.ValidationMessageFor(model => model.Department)
</div>
<div class="row">
@Html.LabelFor(model => model.Telephone)
@Html.EditorFor(model => model.Telephone)
@Html.ValidationMessageFor(model => model.Telephone)
</div>
<div class="row">
@Html.LabelFor(model => model.Mobile)
@Html.EditorFor(model => model.Mobile)
@Html.ValidationMessageFor(model => model.Mobile)
</div>
<div class="row">
@Html.LabelFor(model => model.Address)
@Html.EditorFor(model => model.Address)
@Html.ValidationMessageFor(model => model.Address)
</div>
<div class="row">
@Html.LabelFor(model => model.Desc)
@Html.TextAreaFor(model => model.Desc)
@Html.ValidationMessageFor(model => model.Desc)
@Html.Hidden("Status",true)
</div>
<div class="row">
<input type="submit" value="注册" />
<a href="javascript:history.go(-1)">返回</a>
@*@Html.ActionLink("返回", "Index")*@
</div>




}
[解决办法]
1. 你View的名字是否正确。
2. 确定你的注册按钮标签是不是在form表单里面。另外把form 标签的属性 method="post" 写上
3.可以试着把注册按钮弄成 button类型 ,用JQuery 提交表单 $("#表单id").submit(); 注意输入值要在表单标签里面。


[解决办法]

探讨

引用:
一个是打开Register页面,一个是提交呀。这个没问题的

引用:

Register怎么又两个方法?

感觉就是这里有问题。。。没听过打开提交分两个的

热点排行