Edison
Edison

Reputation: 109

passing string with html tags to controller in asp.net mvc

I'm using asp.net mvc2 and I want to implement a rich text area, and passing the contents in this textarea to controller. However, I found that since the contents of rich text area contains html tags, such as "
", it cannot be passed to controller. If I remove this html tags using regex expression, everything works well.

what can I do to pass these contents containing html tags to controller?

Upvotes: 3

Views: 4160

Answers (1)

thangchung
thangchung

Reputation: 2030

2 ways you can do in this case + Put some line of configuration into the web.config file

<configuration>
    <system.web>
        <pages validateRequest="false" />
        <httpRuntime requestValidationMode="2.0" />
    </system.web>
<configuration>
  • Put one attribute ([ValidateInput(false)]) onto the action that you want to posting back on the server side
public class DummyController : Controller
    {
        [ValidateInput(false)]
        public ActionResult Save(FormData formData)
        {
            return View();
        }
    }

Upvotes: 11

Related Questions