使用MVS Razor视图有条件地显示标签

时间:2016-06-21 21:37:04

标签: c# asp.net-mvc razor

此代码:

<td class="text-left">
    @Html.RestrictedActionLink("Edit", "Edit", "Parameter", new[] { "Admin" }, this.User, new { vendorId = Model.VendorId, effectiveDate = Model.EffectiveDate, createNew = false })
    @Html.RestrictedActionLink("Copy", "Edit", "Parameter", new[] { "Admin" }, this.User, new { vendorId = Model.VendorId, effectiveDate = Model.EffectiveDate })
    @Html.RestrictedActionLink("Cancel...", "", "", new[] { "Admin" }, User, null, new { @class = "CancelParam", vendorId = Model.VendorId, effectiveDate = Model.EffectiveDate})                   
</td>

...渲染3个achor标签:

<td class="text-left">
    <a href="/Parameter/Edit?vendorId=CT1%20%20&amp;effectiveDate=07%2F01%2F2016%2000%3A00%3A00&amp;createNew=False">Edit</a>
    <a href="/Parameter/Edit?vendorId=CT1%20%20&amp;effectiveDate=07%2F01%2F2016%2000%3A00%3A00">Copy</a>
    <a class="CancelParam" effectiveDate="07/01/2016 00:00:00" href="javascript:void(0)" vendorId="CT1  ">Cancel...</a>                
</td>

但是这个代码,我添加的代码只显示了取消和复制链接,如果设置了相关的模型bool属性,

<td class="text-left">
    @Html.RestrictedActionLink("Edit", "Edit", "Parameter", new[] { "Admin" }, this.User, new { vendorId = Model.VendorId, effectiveDate = Model.EffectiveDate, createNew = false })
    @{
        if (Model.AllowCancel)
        {
            Html.RestrictedActionLink("Copy", "Edit", "Parameter", new[] { "Admin" }, this.User, new { vendorId = Model.VendorId, effectiveDate = Model.EffectiveDate });
        }

        if (@Model.AllowCancel)
        {
            Html.RestrictedActionLink("Cancel...", "", "", new[] { "Admin" }, User, null, new { @class = "CancelParam", vendorId = Model.VendorId, effectiveDate = Model.EffectiveDate, disabled = !Model.AllowCancel });
        }
    }

在HTML中没有产生任何复制或取消链接,即使在我追踪时,我目睹了RestrictedActionLink方法被调用。

我是一个剃刀菜刀,还有很多其他的话可以在Noob面前出现。

1 个答案:

答案 0 :(得分:3)

这里的语法略有错误。试试这个:

"write: No such file or directory"