在Razor视图中切换禁用按钮ASP.NET MVC 4 [英] Toggle disable button in Razor view ASP.NET MVC 4

查看:73
本文介绍了在Razor视图中切换禁用按钮ASP.NET MVC 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图基于if语句在Razor视图中启用或禁用html按钮之间进行切换.无论if语句的值如何,都将禁用该按钮.

I'm trying to toggle between enabling or disabling an html button from a Razor view based on an if statement. This disables the button regardless of the value of the if statement.

@{
    disabled = "";
    if (Model.User.PublicId == ViewBag.SiteUser.PublicId)
    {
        followClass += " you";
        followText = "You";
        disabled = "disabled";
    }
}

<button class="@followClass" disabled="@(disabled)">@(followText)</button>

推荐答案

简单修复,只需从按钮定义中删除disable ="=".

Simple fix, just remove disabled="" from the button definition.

<button class="@followClass" @disabled >@followText</button>

这篇关于在Razor视图中切换禁用按钮ASP.NET MVC 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆