MVC3 Model Substitution Does Not Update Partial View

Any ideas why, after adding the model binding to the controller, the partial view is no longer updated:

All I did was change the signature:

from

public ActionResult About2() 

in

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

and here is 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> } 

I added an example: http://www.sendspace.com/file/7boodv

Thanks,

+4
source share
1 answer

I downloaded your project and the problem is in the following code:

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

using this attribute [AcceptVerbs(HttpVerbs.Post)] , this is not a problem, you cannot open your desired page without using GET for your request.

Of course, deleting this attribute worked fine, but if you need to reserve it, add another action with the same name to send a GET request to your page as follows:

 public ActionResult About2() { // Initialization code for About2 page } 

What is it. Feel free to ask if it still works, thanks.

0
source

Source: https://habr.com/ru/post/1345897/


All Articles