在我的列表控制器中,
public ActionResult GetByList(string name, string contact) { var NameCollection = Service.GetByName(name); var ContactCollection = Service.GetByContact(contact); return View(new ListViewModel(NameCollection ,ContactCollection)); }在我调用的 ASPX 页面中,
In ASPX page I call,
<a href="<%:Url.Action("GetByList","Listing" , new {name= "John"} , new {contact="calgary, vancouver"})%>"><span>People</span></a>我的 ASPX 代码有问题...我可以提取姓名 john 的记录.但是当我给 contact="calgary, vancouver" 时,网页会出错.
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.
如何调用Url.Action 中的两个参数.我尝试了以下但似乎也错了.
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> 推荐答案以下是正确的重载(在您的示例中,您缺少 routeValues 的关闭 }匿名对象,因此您的代码将引发异常):
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>这将成功调用传递两个参数的 GetByList 控制器操作:
which will successfully invoke the GetByList controller action passing the two parameters:
public ActionResult GetByList(string name, string contact) { ... }更多推荐
Url.Action 参数?
发布评论