如何控制宽度和小数位都为一个文本框? [英] How to control both the width and decimal places for a text box?

查看:106
本文介绍了如何控制宽度和小数位都为一个文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MVC的Razor视图

Html.EditorFors小数可以与Dataannotations被控制,但没有容易(如果有的话)的方式来控制的宽度(它们不采取htmlAttributes并设置一个CSS类的宽度没有任何影响)。

Html.TextBoxFors允许与htmlAttributes宽度的容易控制,但没有容易(如果有的话)的方式来控制所述小数位

你如何编辑的文本框,你可以控制的宽度和小数两者兼而有之?


解决方案

  

和设置一个CSS类的宽度没有效果。


我想这是因为你有一个不正确的CSS选择器。

您可以这样做,例如:

 < D​​IV CLASS =MyRule的>
    @ Html.EditorFor(X => x.FooBar)
< / DIV>

,然后在你的CSS文件:

  .myrule输入{
    宽度:200像素;
}

由于使用EditorFor打电话时,你可以写一个自定义编辑模板,然后指定该模板的名称替代:

  @ Html.EditorFor(X => x.FooBar,MyTemplate的)

MVC RAZOR VIEW

Html.EditorFors decimal places can be controlled with Dataannotations but there is no easy (if any) way to control the width (they don't take htmlAttributes and setting a css class with a width has no effect).

Html.TextBoxFors allow easy control of the width with htmlAttributes but there is no easy (if any) way to control the decimal places.

How do you get an edit text box that you can control both the width and the decimal places?

解决方案

and setting a css class with a width has no effect

I suppose that's because you have an incorrect CSS selector.

You could do this for example:

<div class="myrule">
    @Html.EditorFor(x => x.FooBar)
</div>

and then in your CSS file:

.myrule input {
    width: 200px;
}

As an alternative you could write a custom editor template and then specify the name of this template when using the EditorFor call:

@Html.EditorFor(x => x.FooBar, "MyTemplate")

这篇关于如何控制宽度和小数位都为一个文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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