ASP.NET MVC3 - textarea的与@ Html.EditorFor [英] ASP.NET MVC3 - textarea with @Html.EditorFor

查看:546
本文介绍了ASP.NET MVC3 - textarea的与@ Html.EditorFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ASP.NET MVC3应用程序,我也形成了附加的消息。当VS2010创建默认视图我只对字符串数据的文本输入,但我想有消息文本的textarea。我怎么可以用剃刀语法做到这一点。

输入文字是这样的:

  @ Html.EditorFor(型号=> model.Text)


解决方案

您可以使用<$c$c>[DataType]属性对你这样的视图模型:

 公共类MyViewModel
{
    [数据类型(DataType.MultilineText)
    公共字符串文本{搞定;组; }
}

,然后你可以有一个控制器:

 公共类HomeController的:控制器
{
    公众的ActionResult指数()
    {
        返回查看(新MyViewModel());
    }
}

和视图这你想要做什么:

  @model AppName.Models.MyViewModel
@using(Html.BeginForm())
{
    @ Html.EditorFor(X =&GT; x.Text)
    &LT;输入类型=提交VALUE =OK/&GT;
}

I have ASP.NET MVC3 app and I have also form for add news. When VS2010 created default view I have only text inputs for string data, but I want to have textarea for news text. How I can do it with Razor syntax.

Text input look like this:

@Html.EditorFor(model => model.Text)

解决方案

You could use the [DataType] attribute on your view model like this:

public class MyViewModel
{
    [DataType(DataType.MultilineText)]
    public string Text { get; set; }
}

and then you could have a controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View(new MyViewModel());
    }
}

and a view which does what you want:

@model AppName.Models.MyViewModel
@using (Html.BeginForm())
{
    @Html.EditorFor(x => x.Text)
    <input type="submit" value="OK" />
}

这篇关于ASP.NET MVC3 - textarea的与@ Html.EditorFor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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