为什么Ajax.BeginForm不传递表单值? [英] Why Ajax.BeginForm does not pass form values?
本文介绍了为什么Ajax.BeginForm不传递表单值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过展示调用Ajax.BeginForm的局部视图,但我不能接受我的表格值(我需要隐藏输入,BOOKID的值,控制器,例如5)。
I'm trying to show a partial view via calling Ajax.BeginForm, but I can't receive the values of my form(I need to get the value of hidden input, bookId, in controller, e.g 5).
//查看
@using (Ajax.BeginForm("Detail", "Books", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "ShowBookDiv" }))
{
<input type="hidden" id="bookId" value="5" />
<input type="submit" id="sBtn" value="Details" />
}
//控制器
[HttpGet]
public ActionResult Detail(string bookId)
{
if (Request.IsAjaxRequest())
{
var a = Request["bookId"].ToString();
// some code to get details
return PartialView("ShowBooks", details);
}
...
}
当我跟踪code在控制器的BookID为空!
When I trace the code in Controller bookId is null!
推荐答案
我添加了名属性为隐藏字段和它的作品!真奇怪!
I've added the "name" property to hidden field and it works !!! really strange!
<input type="hidden" name="bookId" id="bookId" value="5" />
这篇关于为什么Ajax.BeginForm不传递表单值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文