MVC Html.TextAreaFor字符限制 [英] MVC Html.TextAreaFor Character limitation

查看:81
本文介绍了MVC Html.TextAreaFor字符限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有TextArea的View,我希望此TextArea接受大于最大4000个字符的字符串.我的模型建立了四个字符串字段:Body,BodyExt1,BodyExt2等.有没有一种方法可以将字符串从曾经的TextArea拆分为四个不同的字段?

我尝试在Controller的PostBack中执行此操作,但是我收到一个EntityValidationError,表示它超过了4000个字符的限制.

有人可以举一个例子说明我如何解决或解决这个问题吗?

谢谢.

更新:
这是MVC3.数据库"字段设置为nvarchar4000.

I have a View that has a TextArea I would like this TextArea to accept strings that are larger than the max 4000 characters. My Model has four string fields built: Body, BodyExt1, BodyExt2, etc. Is there a way that I can split the string from the once TextArea into the four different fields?

I tried doing this in the Controller''s PostBack, but I am getting an EntityValidationError saying the it exceeds the 4000 character limit.

Could someone give me an example of how I would solve or get around this issue?

Thanks.

Update:
This is MVC 3. The Database fields are set to nvarchar4000.

推荐答案

mvc 2
mvc 2
<![CDATA[<%= Html.TextBox("username", "", new { @maxlength = "5000", @autocomplete = "off" }) %>]]>



或mvc 3



or mvc 3

@Html.TextBoxFor(x => x.name, new { @maxlength = "5000"})



您可能需要检查的另一件事是数据库中该特定字段的字符串限制.



Another thing you might need to check is your string limit for that particular field in your database.


您好,..

您认为:
Hi there.. Try this..

In your view:
<![CDATA[<%=Html.TextAreaFor(m=>m.Address)%>]]>
<![CDATA[<%=Html.ValidationMessageFor(m=>m.Address)%>]]>



在您的模型中:



In your model:

[Required(ErrorMessage = "Please Enter Address")]
[DisplayName("Address*")]
[StringLength(50, ErrorMessage="Must Not Exceed 50 Char")]
public string Address
{
    set
    {
        strAddress = value;
    }
    get
    {
        return strAddress;
    }
}



现在这段代码可以正常工作了.



Now this code will work...


这篇关于MVC Html.TextAreaFor字符限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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