ASP.NET MVC beta update using ajax form

I got this ajax form in an ASP.NET MVC beta app:

    <%using (this.Ajax.BeginForm("Edit", "Subscriber",
new AjaxOptions { OnSuccess = "onEditResult", HttpMethod = "GET" }))  
            {%>
                   <%=Html.Hidden("idSub", p.Id.ToString())%>
                     <input type="submit" value="Edit"/><% 
             } %>

      

And my controller method:

[AcceptVerbs(HttpVerbs.Get)]
        public JsonResult Edit(String idSub)
        { (...)
}

      

But idSub is always null before downgrading to beta, I swear I can see this method works!

I have updated the JS (Microsoft Ajax) files and assemblies as recommended.

0


source to share


2 answers


I got my error, it comes from spring integration. In ControllerBase class, getter for IValueProvider (class to get value from route / request / form data) returns _valueProvider like this:

get {
    if (_valueProvider == null && ControllerContext != null) {
         _valueProvider = new DefaultValueProvider(ControllerContext);
    }
    return _valueProvider;
}

      

Since my controller is being instantiated with the spring factory of the MVCContrib project, it was configured as a singleton, so the ValueProvider has the ControllerContext property value from the first request, not the current one.

So this line in the DefaultValueProvider class:



HttpRequestBase request = ControllerContext.HttpContext.Request;

      

always returned the first Request object that has no QueryString and therefore no parameter value for my method.

I am changing my spring config to get a new Controller instance which I think is good and now the method parameter is correctly filled.

0


source


I found this code works (replacing GET with POST verb and using formcollection as a parameter of the controller method)



    using (this.Ajax.BeginForm("BeginEdit", "Subscriber", 
new AjaxOptions { OnSuccess = "onEditResult", HttpMethod = "POST" }))  
    {%>
         <%=Html.Hidden("idSub", p.Id.ToString())%>
         <input type="submit" value="Edit"/><% 
    }


 [AcceptVerbs(HttpVerbs.Post)]
 public JsonResult BeginEdit(FormCollection form)
 {
    String idSub = form["idSub"];
 }

      

0


source







All Articles