ASP. NET MVC submission model cannot receive

Source: Internet
Author: User
Tags httpcontext

[HttpPost]
[ValidateInput (False)]
Public ActionResult AddNews1 (_54young_news_model.model.gou54contentall contentmodel, _54young_news_ Model.model.gou54user Usermodel)
{}

Found with some special symbols can not be submitted, and then thought that the front-end problem, the model is removed on it. It is thought that there is a special symbol that affects the turn model.

Wrote a request to the model, but still an error.

<summary>
The content of the requested request is converted to model
Cza
2016-5-30 19:06:21
</summary>
<param name= "Context" ></param>
<returns></returns>
public static T Converttomodel ()
{
HttpContext context=system.web.httpcontext.current;
T t = new t ();
propertyinfo[] Propertys = T.gettype (). GetProperties ();
foreach (PropertyInfo pi in Propertys)
{
if (!pi. CanWrite)
Continue
Try
{
Object value = Context. Request[pi. Name];
if (value! = NULL && value! = DBNull.Value)
{

if (value. ToString ()! = "")
Pi. SetValue (t, Convert.changetype (value, pi). PropertyType), null);//This step is important for type conversion
Else
Pi. SetValue (t, value, NULL);

}
}
Catch
{ }
}

return t;
}

On-line data see can be added in Web. config, but it is too dangerous to be global.

<system.web>
<pages validaterequest= "false"/>
</system.web>

And then you see that. You can add this validation method in front of the method

[HttpPost]
[ValidateInput (False)]
Public ActionResult AddNews1 (_54young_news_model.model.gou54contentall contentmodel, _54young_news_ Model.model.gou54user Usermodel)
{

}

ASP. NET MVC submission model cannot receive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.