Html.BeginForm中的局部视图? [英] Html.BeginForm in a partial view?
问题描述
我有一个使用Html.BeginForm从文本框提交一个值,控制器code块。当我把这个视图,它工作正常。也就是说,控制器的动作方法被调用。然而,当我把code的此块将在观统领呈现局部视图中,控制器的动作不会被调用。
I have a block of code that uses the Html.BeginForm to submit a value from textbox to controller. When I put this in a View, it works fine. That is, the controller's action method is called. However, when I place this block of code inside a partial view that will get rendered in the View, the controller's action never gets called.
不知道这是通常的行为,或者如果我失去了一些东西...
Not sure if this is the usual behavior or if I am missing something...
@using (Html.BeginForm("TestAction", "Home", FormMethod.Post, new { id = "formId" }))
{<table>
<tr>
<td>Data Date</td>
<td>@Html.TextBox("date")</td>
</tr>
<tr>
<td></td>
<td><input id="btnRun" type="submit" value="submit" /></td>
</tr>
}
控制器:
[HttpPost]
public ActionResult TestAction(string date)
{
[doing something......]
return View();
}
在此先感谢!
推荐答案
通常 @ Html.BeginForm()
呈现&LT;形式&GT;
标签的动作指向回路线的细节,得到了它在这里。因此,在局部视图,你实际上渲染返回到外层页面。 (是啊,让人刮目相看。)如果你想直接具体的形式张贴到特定的路线,增加额外的参数给 @ Html.BeginForm()
。见<一href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.html.formextensions.beginform(v=vs.108).aspx\" rel=\"nofollow\">http://msdn.microsoft.com/en-us/library/system.web.mvc.html.formextensions.beginform(v=vs.108).aspx
Typically @Html.BeginForm()
renders the <form>
tag's action to point back to the route details that got it here. Thus in partial views, you're actually rendering back to the outer page. (Yeah, mind-bending.) If you want to specifically direct the form post to a particular route, add additional parameters to the @Html.BeginForm()
. See http://msdn.microsoft.com/en-us/library/system.web.mvc.html.formextensions.beginform(v=vs.108).aspx
这篇关于Html.BeginForm中的局部视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!