I can't turn off Request Validation for an ASP.NET MVC Controller

前端 未结 4 2072
轮回少年
轮回少年 2020-12-20 14:25

I am trying to turn off Request Validation for all action methods in a controller by doing this:

[ValidateInput(false)]
public class MyController : Controller         


        
4条回答
  •  萌比男神i
    2020-12-20 14:56

    Can you post your controller file and your view file.

    This works;

    MytestController--------------------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Mvc.Ajax;
    
    namespace testapp.Controllers
    {
        [ValidateInput(false)]
        public class MyTestController : Controller
        {
    
            public ActionResult Index()
            {
                return View();
            }
    
        }
    }
    

    MyTest(Index)-------------------------------------------------------

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    
    
    
    
    
        Index
    
    
     <% using (Html.BeginForm()) { %>
     <%= Html.TextBox("test")%>
     
     <%} %>
    
    
    

提交回复
热议问题