Asp.net mvc 字符串文字mvc按钮中的字符太多

Asp.net mvc 字符串文字mvc按钮中的字符太多,asp.net-mvc,Asp.net Mvc,我正在将我的@Html.ActionLink(“Name”、“Action”、new{@class='button'、@id='addItemEIqM'})更改为按钮,以便它们可以包含数据角色,并处理动态列表控件 留给我的是: <input type="button" value="Add" onclick="location.href='@Url.Action("ExistingManager","Pa_Ipv4")'" data-containerPrefix="@ViewData['

我正在将我的
@Html.ActionLink(“Name”、“Action”、new{@class='button'、@id='addItemEIqM'})更改为按钮,以便它们可以包含
数据角色
,并处理动态列表控件

留给我的是:

<input type="button" value="Add" onclick="location.href='@Url.Action("ExistingManager","Pa_Ipv4")'" data-containerPrefix="@ViewData['ContainerPrefix']" class="button" id="addItemEIpM"/>


我收到的错误是字符文本中的字符太多,我所写的内容中有什么是非法的?

在C#中不能对字符串文本使用单引号。单引号用于字符。您的错误是:

...erPrefix="@ViewData['ContainerPrefix']"...
您应该使用双任务:

...erPrefix="@(ViewData["ContainerPrefix"])"...

您可以将
数据-
属性添加到
@Html.ActionLink()
中,因此似乎没有必要这样做最初尝试过,但没有成功,所以按下了Html按钮。然后我们将再次研究它。它只需要是
新的{data_containerPrefix=ViewData[“containerPrefix”],@class=“button”}
(需要使用下划线字符,而不是连字符)就可以解释它了。。。谢谢