在 html 表单中有大量的模型绑定示例,但我想知道是否可以,如果可以,如何使用模型绑定来处理 ActionLinks/GET 请求。
所以,给定以下模型
public class Lurl
{
public string Str {get;set;}
public char Chr {get;set;}
public double Dbl {get;set;}
}
和以下路线(我不确定这将如何形成;我展示它是为了展示我希望 URL 如何展示属性 Str、Chr 和 Dbl)
routes.MapRoute(
"LurlRoute",
"Main/Index/{str}/{chr}/{dbl}",
new
{
controller = "Main",
action = "Index",
lurl = (Lurl)null
}
);
我想在我的控制器中以这种方式使用它
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Index(Lurl lurl)
{
/* snip */
}
在我的页面中以这种方式(两种可能的选择;还有更多吗?)
<div class="links">
<%Html.ActionLink("Link one", "Index", new { lurl = Model })%><br />
<%Html.ActionLink("Link two", "Index",
new { str = Model.Str, chr = Model.Chr, dbl = Model.Dbl })%>
</div>
模型绑定基础设施可以做到这一点吗?如果是这样,需要对我的样品做些什么才能让它们发挥作用?