如何将参数从@ Url.Action传递到控制器功能 [英] how to pass parameter from @Url.Action to controller function
本文介绍了如何将参数从@ Url.Action传递到控制器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个函数CreatePerson(int id)
,我想从@Url.Action
传递id
.
I have a function CreatePerson(int id)
, I want to pass id
from @Url.Action
.
下面是参考代码:
public ActionResult CreatePerson(int id) //controller
window.location.href = "@Url.Action("CreatePerson", "Person") + id";
上面的代码无法将id
值传递给CreatePerson
函数.
the above code fails to pass id
value to CreatePerson
function.
推荐答案
您可以通过以下方式传递它:
you can pass it this way :
Url.Action("CreatePerson", "Person", new RouteValueDictionary(new { id = id }));
OR也可以通过这种方式
OR can also pass this way
Url.Action("CreatePerson", "Person", new { id = id });
这篇关于如何将参数从@ Url.Action传递到控制器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文