vote up 0 vote down
star

I got this ajax form in a ASP.NET MVC beta application :

    <%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 the idSub is always null, before upgrading to the beta I swear I see this method working !

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

flag
add comment

2 Answers:

vote up 0 vote down

I've found that this code works (replacing the GET by the POST verb and using the formcollection as the 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"];
 }
link|flag
add comment
vote up 0 vote down
check

I got my error, it's coming from the spring integration. In the ControllerBase class, the getter for the IValueProvider (the class to get the value from either route data/querystring/form) return the _valueProvider like this :

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

As my controller are build by the Spring factory from MVCContrib project, it was configured as singleton, so the ValueProvider has a ControllerContext property value from the first request and not the current one.

So this line in the DefaultValueProvider class :

HttpRequestBase request = ControllerContext.HttpContext.Request;

always returned the first Request object ,which has no QueryString and so no parameter value for my method.

I change the Spring configuration to get a new instance of Controller which I think is a good thing and now the method parameter is correctly populated.

link|flag
add comment

Your Answer:

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.