Ajax.BeginForm 提交后不在指定ID的元素中显示结果
Ajax.BeginForm 提交后不在指定ID的元素中显示结果
Ajax.BeginForm表单不是异步请求的吗?应该是页面无刷新,然后在表单提交完成后将信息反馈到当前页面的指定ID的元素中显示。
可是我的为什么死活不显示在当前页面!!每次都是跑到新页面里。
View视图代码:
@{
ViewBag.Title = "AjaxForm";
}
@using (Ajax.BeginForm("AjaxFormPost",new AjaxOptions(){ HttpMethod="POST", UpdateTargetId="ibox"}))
{
<input type="text" name="name" />
<input type="submit" value="提交" />
<div id="ibox" style="width:300px; height:100px; margin:0px auot; border:1px solid #ccc;"></div>
}
控制器代码
mvc3 asp.net
public string AjaxFormPost(string name)
{
//List<string> ew = new List<string>();
//ew.Add(name);
//return View(ew);
return name;
}
[解决办法]
把结果显示放到ajax form 外面来
@{
????ViewBag.Title?=?"AjaxForm";
}
?
????<div?id="ibox"?style="width:300px;?height:100px;?margin:0px?auot;?border:1px?solid?#ccc;"></div>?
@using?(Ajax.BeginForm("AjaxFormPost",new?AjaxOptions(){?HttpMethod="POST",?UpdateTargetId="ibox"}))
{
????<input?type="text"?name="name"?/>
????<input?type="submit"?value="提交"?/>
}