how to pass parameter with @url.action to controller

江枫思渺然 提交于 2019-11-27 06:36:31

问题


i have following code snippet i want to pass data-id="0" with my @url.action , how can i do this

<a class="v-patient pointer" data-id="0" href="@Url.Action("View1", "Task")">View Patient</a></td>

my task controller

public ActionResult View1(string id)
        {
            return View();
        }

回答1:


If is was an ActionLink you would do this:

@Html.ActionLink("View1", "Task", new {id=0}, null);

So in your case, using Url.Action() it would be:

href="@Url.Action("View1", "Task", new {id=0})"

Which in your sample is:

<a class="v-patient pointer" data-id="0" href="@Url.Action("View1", "Task", new {id=0})">View Patient</a></td>


来源:https://stackoverflow.com/questions/24825840/how-to-pass-parameter-with-url-action-to-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!