Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 16-Feb-12 8:51am
v2

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


or mvc 3
C#
@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.
 
Share this answer
 
Comments
grasshopper003 16-Feb-12 14:59pm    
Thanks for the suggestion, but I am still getting the same error...
Error: The field Body must be a string or array type with a maximum length of '4000'.

@Html.TextAreaFor(model => model.Body,new{id = "body", rows = "10", htmlEncodeOutput="true", maxlength = "5000"})
Dean Oliver 17-Feb-12 0:17am    
is your body property a string? "model.Body"
Hi there.. Try this..

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


In your model:
C#
[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...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900