Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 2 Html.textboxforformat和css类_Asp.net Mvc 2_Html.textbox - Fatal编程技术网

Asp.net mvc 2 Html.textboxforformat和css类

Asp.net mvc 2 Html.textboxforformat和css类,asp.net-mvc-2,html.textbox,Asp.net Mvc 2,Html.textbox,下面的两行代码工作得很好,但我想将它们结合起来。 我的意思是:我想在第一行代码中使用@class。 我该怎么做 <%: Html.TextBoxFor(model => model.Product.Price, String.Format("{0:f}", Model.Product.Price))%> <%: Html.TextBoxFor(model => model.Product.Name, new { @class = "textBox150" })%&

下面的两行代码工作得很好,但我想将它们结合起来。 我的意思是:我想在第一行代码中使用@class。 我该怎么做

<%: Html.TextBoxFor(model => model.Product.Price, String.Format("{0:f}", Model.Product.Price))%>

<%: Html.TextBoxFor(model => model.Product.Name, new { @class = "textBox150" })%>
model.Product.Price,String.Format(“{0:f}”,model.Product.Price))%>
model.Product.Name,新的{@class=“textBox150”})%>
谢谢


菲利普

恐怕没有干净的方法可以做到这一点。有两种可能性:

  • 使用产品属性的编辑器模板:

    <%: Html.EditorFor(x => x.Product) %>
    
    然后修改CSS规则:

    .container150 input {
        // some rule that applies to the textbox
    }
    

  • 我知道我来晚了,但我刚刚找到了解决这个问题的办法:

    <%: Html.TextBoxFor(model => model.StartDate, new { @class = "datepicker", Value=String.Format("{0:d}", Model.StartDate) })%>
    
    model.StartDate,新的{@class=“datepicker”,Value=String.Format(“{0:d}”,model.StartDate)})%%>
    
    再说一遍,可能已经晚了,但我相信更好的解决方案是使用插件(也可以作为nuget软件包提供)

    为什么使用插件比使用输入格式更好?嗯,当有人修改输入时,如果不使用插件,您将失去格式化


    您可以找到它的用法和工作原理的演示。

    我花了很长时间才找到这个答案。谢谢@切达-谢谢你,伙计。这省了我头上的一些头发!
    .container150 input {
        // some rule that applies to the textbox
    }
    
    <%: Html.TextBoxFor(model => model.StartDate, new { @class = "datepicker", Value=String.Format("{0:d}", Model.StartDate) })%>