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?
+2
A:
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;
}
}
TheDeeno
2008-08-30 17:52:00
+3
A:
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.
matt
2008-08-30 17:57:16
+1
A:
Thanks Matt for pointing me to the right direction. After you told me about UpdateModel, I found this helpful post.
http://blog.rodj.org/archive/2008/09/01/asp.net-mvc-update-preview-4-to-preview-5.aspx
Kevin Faustino
2008-08-31 11:05:24
A:
Hi Kevin, could you redo that link in something like tinyurl.com?
I need this info too but can get that mega-link to work.
IainMH
2008-09-04 13:32:37
http://is.gd/6LqB
spoon16
2008-11-09 08:20:44