I had an earlier problem before and was unable to fix the issue but I have worked at it over several hours and was hoping that someone with more knowledge than me can help solve this issue.
I am having a really difficult time binding the AllowHtml attribute to a textbox, on another controller I have it working perfectly but now that I have multiple models in 1 view it doesn't work this is how it looks
// Model name is : thread
[AllowHtml]
public string post { get; set; }
// those 2 are the same model 1 is a foreach and the other is singular
public class homepage
{
public IEnumerable<thread> threadings { get; set; }
public thread threader { get; set; }
}
I have 2 models under homepage , The IEnumerable is a foreach that displays a list of cars and the thread threader exist only so I can bind the field post to allowHtml but what is happening is that the form submits but that field is always blank
top is the code and beneath is the source code This is my first option/try
results: The form submitted but the Post textarea was null in the database
@Html.TextAreaFor(x => x.threader.post)
<textarea cols="20" id="threader_post" name="threader.post" rows="2">
The second option rewriting my code like this
results: The form would not submit at all
@Html.TextAreaFor(x => x.threader.post, new { @id = "post" })
<textarea cols="20" id="post" name="threader.post" rows="2">
The third option
results: This one worked and I was finally able to submit the form with HTML inside the Post but i had to use validate input false
@Html.TextAreaFor(x => x.threader.post, new { @id = "post",@Name="post" })
<textarea Name="post" cols="20" id="post" name="threader.post" rows="2">
// and on top of the action I put
[ValidateInput(false)]
i wanted to show the different steps I took and the results I got from each now this third option above worked perfectly, but how can I make this work without the [ValidateInput(false)] as that is bad practice since I got other fields that need validation. oh and without [ValidateInput(false)] the form does not submit. Any suggestions would be great.
oh and if it makes any difference this is inside a partialView