MVC3模型绑定不会更新局部视图

时间:2011-03-30 15:00:55

标签: asp.net-mvc-3 model-binding

任何想法为什么在将模型绑定添加到控制器后,部分视图不再更新:

我所做的就是改变签名:

从:

public ActionResult About2()

为:

public ActionResult About2([Bind(Prefix = "SomePropertyToBind")] String modelString)

这是Ajax.BeginForm:

@using (Ajax.BeginForm("About2", "Home", new AjaxOptions { UpdateTargetId = "property22", InsertionMode = InsertionMode.Replace }))
{    
    @Html.DropDownListFor(m => m.ModelTest.SomePropertyToBind, new SelectList(Model.ModelTest.list, "property1", "property2"))

    <button type="submit" id="test">Click me</button>    
}

我附上了一个示例:http://www.sendspace.com/file/7boodv

谢谢,

1 个答案:

答案 0 :(得分:0)

我下载了您的项目,问题在于以下代码:

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult About2([Bind(Prefix = "SomePropertyToBind")] String modelString)
        {

使用此属性[AcceptVerbs(HttpVerbs.Post)]是问题所在,如果没有GET操作来处理您的请求,则无法打开所需的网页。

当然,删除此属性的效果非常好,但如果您需要保留此属性,请添加另一个具有相同名称的操作,以便向您的页面提供GET请求,如下所示:

public ActionResult About2()
        {

   // Initialization code for About2 page

}

就是这样。随便问一下它是否还在工作,谢谢。

相关问题