简体   繁体   English

MVC3 HTML按钮

[英]MVC3 HTML button

I am using MVC3 and I dont want to use Microsoft.Web.Mvc 我正在使用MVC3,但我不想使用Microsoft.Web.Mvc

How do I convert this code to be used in MVC3 ? 如何转换此代码以在MVC3中使用? The view engine is .aspx 视图引擎是.aspx

Html.Button ("abc", "Button abc", HtmlButtonType.Button)  

and also this script 还有这个脚本

$("button[name=abc]").attr("disabled",true);  

Any feedback is appreciated ? 任何反馈表示赞赏吗?

HTML Markup for your button : 按钮的HTML标记

<input type="button" name="abc" disabled="true" value="Button abc" />

ASP.NET MVC 3 does not have a built-in HtmlHelper extension method for a button. ASP.NET MVC 3没有用于按钮的内置HtmlHelper扩展方法。 You could always easily create on: 你总是可以轻松地创建于:

public static class YourMvcButtonExtensionMethod
{
    public static MvcHtmlString Button(this HtmlHelper helper, string text,
                                     IDictionary<string, object> htmlAttributes)
    {
        // generate the markup for the input/button
    }
}

So you really have two options: 因此,您确实有两种选择:

  1. use raw HTML markup in your View 在视图中使用原始HTML标记
  2. create your custom extension method ( see above ) 创建您的自定义扩展方法请参见上文

"I am using MVC3 and I dont want to use Microsoft.Web.Mvc" That just sounds confusing... “我正在使用MVC3,但我不想使用Microsoft.Web.Mvc。”这听起来令人困惑……

Anyway you can use the button element instead. 无论如何,您可以改用button元素。

<button disabled='true'>Button abc</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM