Asp.net 将隐式类型化对象转换为querystring
在ASP.NET MVC3中,某些函数(如HtmlHelper.ActionLink)可以接收隐式类型化对象并将其转换为查询字符串Asp.net 将隐式类型化对象转换为querystring,asp.net,asp.net-mvc-3,asp.net-4.0,Asp.net,Asp.net Mvc 3,Asp.net 4.0,在ASP.NET MVC3中,某些函数(如HtmlHelper.ActionLink)可以接收隐式类型化对象并将其转换为查询字符串 @Html.ActionLink("Link", "Action", new { id = 1, params="asd"}) 将导致类似于http://www.localhost.com/controller/Action?id=1¶ms=asd 是否有内置方法将对象的属性转换为querystring格式?假设您有一个视图模型: public class
@Html.ActionLink("Link", "Action", new { id = 1, params="asd"})
将导致类似于http://www.localhost.com/controller/Action?id=1¶ms=asd
是否有内置方法将对象的属性转换为querystring格式?假设您有一个视图模型:
public class MyViewModel
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
}
以及控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new MyViewModel
{
Prop1 = "foo",
Prop2 = "bar"
};
return View(model);
}
}
您可以在视图中使用:
@model MyViewModel
@Html.ActionLink("Link", "Action", new RouteValueDictionary(Model))
在你看来