Question

I am attempting to update a project from ASP.NET MVC Preview 3 to Preview 5 and it seems that Controller.ReadFromRequest(string key) has been removed from the Controller class. Does anyone know of any alternatives to retrieving information based on an identifier from a form?

Was it helpful?

Solution

Looks like they've added controller.UpdateModel to address this issue, signature is:

UpdateModel(object model, string[] keys)

I haven't upgraded my app personally, so I'm not sure of the actual usage. I'll be interested to find out about this myself, as I'm using controller.ReadFromRequest as well.

OTHER TIPS

Not sure where it went. You could roll your own extension though:

public static class MyBindingExtensions {

public static T ReadFromRequest < T > (this Controller controller, string key) 
{
    // Setup
    HttpContextBase context = controller.ControllerContext.HttpContext;
    object val = null;
    T result = default(T);

    // Gaurd
    if (context == null)
        return result; // no point checking request

    // Bind value (check form then query string)
    if (context.Request.Form[key] != null)
        val = context.Request.Form[key];
    if (val == null) 
    {
        if (context.Request.QueryString[key] != null)
            val = context.Request.QueryString[key];
    }

    // Cast value
    if (val != null)
        result = (t)val;

    return result;
}

}

could you redo that link in something like tinyurl.com?

I need this info too but can get that mega-link to work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top