Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 将隐式类型化对象转换为querystring_Asp.net_Asp.net Mvc 3_Asp.net 4.0 - Fatal编程技术网

Asp.net 将隐式类型化对象转换为querystring

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

在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 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))
在你看来