2017-03-11 30 views
0

我有這個代碼om我的視圖。這是很好的工作。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>), 

隨着形象都很好,但鏈接不起作用。

+0

你想做什麼? – Shyju

+0

我編輯我的代碼。請看。 –

回答

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

這很好。

0

改變你的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"'