- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在构建一个 ASP.NET MVC 2 网站,现在,我的 View 中有难看的意大利面条代码,我想将其制作成自定义 HtmlHelper。 View 中的当前代码是:
<%switch (Model.fiFieldTypeID) %>
<%
{
case 1: // Text area
Response.Write(Html.Encode(Html.TextAreaFor(model => model.fiStrValue)));
Response.Write(Html.Encode(Html.ValidationMessageFor(model => model.fiStrValue)));
break;
case 2: // Text box
Response.Write( Html.Encode(Html.TextBoxFor(model => model.fiStrValue)));
Response.Write( Html.Encode(Html.ValidationMessageFor(model => model.fiStrValue)));
break;
etc....
我试图将这段代码封装到一个简洁的小 HtmlHelper 中。我是这样开始的:
public class FormHelpers
{
public static MvcHtmlString GetStreamFieldEditor(this HtmlHelper html, FieldInstance field)
{
string output = "";
switch (field.fiFieldTypeID)
{
case 1: // Text area
output += html.TextAreaFor(field=> field.fiStrValue).ToString();
etc....
我知道我的 lamda 是错误的...但我更担心的是 TextAreaFor
不能用作方法。但是,普通的旧 TextArea
可用。我不想使用 TextArea
因为我需要保留我的模型绑定(bind)。如何在我的自定义 html 帮助程序中使用 TextAreaFor
、TextBoxFor
等?
最佳答案
这个怎么样:
public static class FormHelpers
{
public static MvcHtmlString GetStreamFieldEditor(
this HtmlHelper<YourModelType> html)
{
var model = html.ViewData.Model;
if (model.fiFieldTypeID == 1)
{
return html.TextAreaFor(x => x.fiStrValue);
}
return html.TextBoxFor(x => x.fiStrValue);
}
}
然后:
<%: Html.GetStreamFieldEditor() %>
<%: Html.ValidationMessageFor(x => x.fiStrValue) %>
关于c# - 如何在自定义 HtmlHelper 中使用 Html.TextAreaFor() 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3980370/
我在注册表格中使用了一些 HTML 帮助程序,但其中一些有一个大纲,我的 CSS 中没有包含该大纲。 我尝试删除我认为可能相关的参数。 @Html.TextAreaFor(x => x.correo,
如何在 ASP.NET MVC View 中更改文本区域宽度?我在这里阅读了有关此问题的问题,但没有任何帮助。 @Html.TextAreaFor(m => m.Suggestions, new {
我无法在 atextarea 中设置宽度或列。行/高度工作得很好。有人可以帮忙吗谢谢! @using (Html.BeginForm()) { @Html.AntiForgeryToken()
这可能很简单,但是...... 我有一个包含文本区域的 View :@Html.TextAreaFor(model => model.ContactInfo) 没有任何新行或使用 @Html.Edit
我有一个表单,其中包含一些 TextBoxFor 和 1 个 TextAreaFor 这里是: @Html.LabelFor(m => m.FromName, new {
在 MVC 应用程序中,我必须使用 @HTML.TextAreaFor 来显示数据库中的一些文本,问题是有时文本中可能包含 HTML 标记,而我看不到删除这些标记以仅供显示的方法。 是否可以在 Vie
我在具有 textBox 和 textArea 的表单上遇到问题。该论坛处于共享 View 中。 textBox 正在验证,但 textArea 不是。我经历了很多其他人面临的问题,但似乎无法解决。我
如何在@Html.TextAreaFor 中垂直居中文本? 这是html Description
我正在开发我的第一个 ASP.NET MVC 3 应用程序,我有一个使用 table 的页面显示两列输入元素。它看起来像这样: Description List
我有以下代码可以为用户提供一个文本输入框。 x.Message) %> 输入框只显示为一个我想增加的小区域。为 id="messageEntry" 创建 CSS 对框的大
如何在 mvc 中禁用文本。我正在使用 mvc 4.0。下面是我的代码,我想有条件地表示如果 m.Changes 值长度 > 0 那么它应该被禁用,否则它被启用。这怎么可能? @Html.TextAr
为了在 Bootstrap 选项卡上呈现一个具有完整宽度和几行的注释字段,我现在正在努力几个小时。我想要的是这样的: 到目前为止,我所做的是寻找解决方案/帖子,但没有一个适合我。我的 Razor 代码
我正在使用下面的代码来显示一些文本,它不会改变字体颜色,有人知道为什么吗? m.Component.ApplicationDescription, new { cols = "40%", Style
我有一个数据输入字段,用于收集笔记。每个音符都需要音符数据元素。这是我的模型: public interface INoteDataEntryViewModel : IMobilePageDataCo
我有一个 asp.net mvc View ,允许用户在 textarea 中输入一些描述。 我面临两个问题。 当我扩展文本区域时,它正在扩展而不移动其他 html 元素,或者我无法创建一个 Html
我在表单上有一个非常基本的 @Html.TextAreaFor(),由于某种原因,文本区域的值永远不会进入我的 Controller 。 查看 (Multiple Entries Allowed) @
我正在构建一个 ASP.NET MVC 2 网站,现在,我的 View 中有难看的意大利面条代码,我想将其制作成自定义 HtmlHelper。 View 中的当前代码是:
我正在使用 MVC2 C#。 我有以下问题:如果 !ModelState.IsValid,我将用户发送回无效表单,其中我的文本区域包含“,”或复制文本区域中的任何内容。 x.Address, new
我有一个带有 HTML 的表单。 TextArea 用户可以在其中插入文本(如新闻)。我想允许用户让文本包含链接。我可以将 [AllowHtml] 添加到该字段的属性中,但我不知道如何在文本中添加链接
我在使用 Razor 引擎实现的 View 中有一个 TextArea() 控件。 @Html.TextArea("EventNature",new { style = "width: 200px;
我是一名优秀的程序员,十分优秀!