Url.Action 至 Html.Raw

Url.Action to Html.Raw

我的视图中有此代码。这很好。

   ... onclick="location.href = '@Url.Action("Plan", "Care", new {Area = "HomeC"})'"><img src="~/Content/images/dash/Care.PNG"

如何使用 Html.Raw 执行相同的代码? 我试过这个

  grid.Column(columnName: "Name", header: "", format: @<text>@(item.ListStatus == 1 ? Html.Raw("<button class='btn btn-default btn-plan' title='Care' onclick='location.href = " + "'" + Url.Action("Plan", "Care", new {Area = "HomeC"}) + "''>" +
                                                                        "<img src='/Content/images/dash/Care.PNG' class='img-plan' data-interlocutorid=" + item.UserId + " " +  "data-interlocutorname=" + item.Name + " " + ">" + 
                                                                    "</button>") : Html.Raw(""))
                                                                 </text>),

图像一切正常,但link不工作。

将 Url.Action(...) 周围的单引号改为双引号。

也就是改这部分:

onclick='location.href = " + "'" + Url.Action("Plan", "Care", new {Area = "HomeC"}) + "''

对此:

onclick='location.href = " + "\"" + Url.Action("Plan", "Care", new {Area = "HomeC"}) + "\"'

这将更改渲染输出:

onclick='location.href = '/Care/Plan?Area=HomeC''

至:

onclick='location.href = "/Care/Plan?Area=HomeC"'
 onclick=" + "location.href=" + "'" + Url.Action("Plan", "Care", new {Area = "HomeC"}) + "'" + ">"

这个作品不错。