【问题标题】:Url.Action to Html.RawUrl.Action 到 Html.Raw
【发布时间】:2017-08-02 03:31:16
【问题描述】:

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

   ... 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>),

图片一切正常,但链接不起作用。

【问题讨论】:

  • 你想做什么?
  • 我编辑我的代码。请看。

标签: asp.net asp.net-mvc asp.net-mvc-4 asp.net-mvc-3


【解决方案1】:

将 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"'

【讨论】:

    【解决方案2】:
     onclick=" + "location.href=" + "'" + Url.Action("Plan", "Care", new {Area = "HomeC"}) + "'" + ">"
    

    这很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-20
      • 1970-01-01
      • 1970-01-01
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      相关资源
      最近更新 更多