我想用submit
从我的标记到 ASP.net MVC 操作。
然后我想将请求重定向到另一个网址。
我可以这样做吗?或者MVC只对应ajax?
如果您使用的是Html.BeginForm http://msdn.microsoft.com/en-us/library/dd505244.aspx像这样:
<% using(Html.BeginForm("HandleForm", "Home")) { %>
<fieldset>
<legend>Fields</legend>
<p>
<%= Html.TextBoxFor(m => m.Field1) %>
</p>
<p>
<%= Html.TextBoxFor(m => m.Field2) %>
</p>
<p>
<input type="submit" value="Submit" />
</p>
</fieldset>
<% } %>
然后你的控制器操作可以执行重定向:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult HandleForm(MyModel myModel)
{
// Do whatever you need to here.
return RedirectToAction("OtherAction", myModel);
}
public ActionResult OtherAction(MyModel myModel)
{
return View(myModel);
}
EDIT::上面的示例现在将与以下模型绑定,并且可以在操作之间传递:
public class MyModel
{
public string Field1 { get; set; }
public string Field1 { get; set; }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)