我对ASP.NET MVC 2非常陌生。
我正在尝试从Custom Login Screen创建简单的登录屏幕(教程在MVC 4中)
这是我的登录视图,其余模型和控制器与链接示例中描述的相同。
<div class="editor-label">
<%=Html.LabelFor(u => u.UserName)%>
</div>
<div class="editor-field">
<%=Html.TextBoxFor(u => u.UserName)%>
<%=Html.ValidationMessageFor(u => u.UserName)%>
</div>
<input type="submit" value="Log In" />
如何将它与模型和控制器链接?
请帮忙
答案 0 :(得分:1)
如果您使用 razor 作为视图引擎,请尝试使用 Html.BeginForm()进行表单提交。
示例:
<% using (Html.BeginForm("Action", "Controller", null, FormMethod.Post, new {@id = "value")) {%>
//Your form goes here
<% } %>
或者
<form method="post" action="/Controller/Action">
//Your form goes here
</form>
答案 1 :(得分:1)
您可以使用Bios提供的答案
在第一种方法中,任何类型为submit
的按钮都会调用
<% using (Html.BeginForm("Action", "Controller", null, FormMethod.Post, new {@id = "value")) {%>
{p>同样适用于<form method="post" action="/Controller/Action">