我正在尝试将一个项目从ASP.NET MVC Preview 3更新到Preview 5,但是似乎Controller.ReadFromRequest(string key)已经从Controller类中移除了。有没有人知道从表单中基于标识符检索信息的替代方法?
我正在尝试将一个项目从ASP.NET MVC Preview 3更新到Preview 5,但是似乎Controller.ReadFromRequest(string key)已经从Controller类中移除了。有没有人知道从表单中基于标识符检索信息的替代方法?
看起来他们添加了controller.UpdateModel来解决这个问题,签名为:
UpdateModel(object model, string[] keys)
我个人没有升级我的应用程序,因此不确定实际使用情况。我也会很有兴趣了解这方面的信息,因为我也在使用controller.ReadFromRequest
。
不确定它去了哪里。但您可以自己编写扩展程序:
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;
}
}
你能把那个链接换成类似 tinyurl.com 的东西吗?
我也需要这个信息,但是无法使用那个巨大的链接。