在列出的控制器我有,
公众的ActionResult GetByList(字符串名称,字符串触点) { VAR NameCollection = Service.GetByName(名); VAR ContactCollection = Service.GetByContact(接触); 返回查看(新ListViewModel(NameCollection,ContactCollection)); }在ASPX页面我打电话,
< A HREF =<%:Url.Action(GetByList,上市,新的{名称=约翰},新{触点=卡尔加里,温哥华})%GT;><跨度>人与LT; / SPAN>< / A>我在ASPX code的一个问题...我可以拉记录的名字John。但是当我给触点=卡尔加里,温哥华,网页去错误。
我如何可以调用Url.Action两个参数。我试过以下,但看上去是错了。
< A HREF =<%:Url.Action(GetByList,上市,新的{名称=约翰,触点=卡尔加里,温哥华} )%GT;><跨度>人与LT; / SPAN>< / A>解决方案
下面是正确的过载(在你的榜样你缺少结束} 到 routeValues 匿名对象,以便您的code会抛出异常):
< A HREF =<%:Url.Action(GetByList,上市,新的{名称=约翰,触点=卡尔加里,温哥华} )%>中与GT; <跨度>人与LT; / SPAN>&所述; / A>假设你使用的是默认路由这应该生成以下标记:
< A HREF =/上市/ GetByList名称=约翰&放大器;放大器;触点=卡尔加里%2C%20vancouver> <跨度>人与LT; / SPAN>&所述; / A>这将成功地调用传递两个参数 GetByList 控制器动作:
公众的ActionResult GetByList(字符串名称,字符串触点){ ...}In listing controller I have,
public ActionResult GetByList(string name, string contact) { var NameCollection = Service.GetByName(name); var ContactCollection = Service.GetByContact(contact); return View(new ListViewModel(NameCollection ,ContactCollection)); }In ASPX page I call,
<a href="<%:Url.Action("GetByList","Listing" , new {name= "John"} , new {contact="calgary, vancouver"})%>"><span>People</span></a>I have a problem in the ASPX code... I can pull the records for the name john. but when I give the contact="calgary, vancouver", the webpage goes to error.
How can I call two parameters in the Url.Action. I tried the below but that seems wrong too.
<a href="<%:Url.Action("GetByList","Listing" , new {name= "John" , contact= " calgary, vancouver" })%>"><span>People</span></a>解决方案
The following is the correct overload (in your example you are missing a closing } to the routeValues anonymous object so your code will throw an exception):
<a href="<%: Url.Action("GetByList", "Listing", new { name = "John", contact = "calgary, vancouver" }) %>"> <span>People</span> </a>Assuming you are using the default routes this should generate the following markup:
<a href="/Listing/GetByList?name=John&contact=calgary%2C%20vancouver"> <span>People</span> </a>which will successfully invoke the GetByList controller action passing the two parameters:
public ActionResult GetByList(string name, string contact) { ... }
更多推荐
Url.Action参数?
发布评论