简体   繁体   中英

Prefix on TextArea of an HTML form built with MVC4

Ok so I am trying to edit another persons asp/mvc application. On 1 of the pages there is a form and part of that form is a TextArea . I am trying to do 2 things.

1) Put a 200 character limit (which I have done via maxlength html code)

2) Put a PreFIX on all entries (user doesn't need to see this). This is my issue -- I was at first OK with a half ass approach of putting a value= into the field however quickly learned that TextArea's do not support this. And that aside the user could delete the prefix.

I have Copy/Paste what I believe are the Areas Of Code related to the function / area... I am a novice at MVC / .net / asp etc. I get lost very fast with bouncing around between 4 files to actually do anything.

How / what would I change here:

CSHTML File (form section):

<td colspan="2">
    <fieldset style="padding: 2px; margin: 2px">
    <legend>Inve Order Comments</legend>
      @Html.TextAreaFor(model => model.InvOrderComments, new {maxlength = "200", style = "width:250px;" })
</fieldset>
</td>

Model.cs - file

 [DisplayName("Inv Order Comments")]
 public string InvOrderComments { get; set; }

Controler.cs file

if (model.IssueOtherOrder && (("Free Form").Equals(model.InvOrderReason) && string.IsNullOrWhiteSpace(model.InvOrderComments)))
{
ModelState.AddModelError("", "Inve Order Comments is a required field.");
ModelState.AddModelError("InvOrderComments", "");
}

Reference.cs - File (found it in there also)

    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)]
public string InvOrderComments {
  get {
    return this.invOrderCommentsField;
      }
      set {
      this.invOrderCommentsField = value;
      }
      }

In the backend you can append the text that you want. OnPostBack from the client, hoping that you are storing this information somewhere, you can check to make sure that the value was not removed by the user and if it was you can just add it back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM