Nhập được thẻ html, javascript vào textbox MVC5

Thảo luận trong 'Lập trình web Asp.net' bắt đầu bởi phamcongson, 4/3/17.

  1. phamcongson
    Tham gia ngày:
    3/6/13
    Bài viết:
    474
    Đã được thích:
    93
    Điểm thành tích:
    28
    Giới tính:
    Nam
    Bị lỗi không nhập được các thẻ html, javascript vào textbox, eiditer,... trong asp.net MVC4, MVC5,..6 lưu xuống cơ sở dữ liệu.
    Mã:
    Server Error in '/' Application.
    A potentially dangerous Request.Form value was detected from the client (Name="<h1>son</h1>").
    Description: ASP.NET has detected data in the request that is potentially dangerous because it might include HTML markup or script. The data might represent an attempt to compromise the security of your application, such as a cross-site scripting attack. If this type of input is appropriate in your application, you can include code in a web page to explicitly allow it. For more information, see go.microsoft.com/fwlink/?LinkID=212874.
    
    Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (Name="<h1>son</h1>").
    
    Để sửa lỗi này bạn thêm đoạn code sau vào Controllers chứa ActionResult cần xử lý:
    Mã:
    [ValidateInput(false)]
    
    Ví Dụ:
    Mã:
    [ValidateInput(false)]//cho phép nhậm dữ liệu html, thẻ vào nút input
      public ActionResult Validate(Studen model)
      {
          if(ModelState.IsValid)
          {
            ModelState.AddModelError("","Chúc mừng bạn đã nhập đúng");
          }
      return View("Index");
      }
    
     
    Cảm ơn đã xem bài:

    Nhập được thẻ html, javascript vào textbox MVC5

    Chỉnh sửa cuối: 4/3/17


Chủ để tương tự : Nhập được
Diễn đàn Tiêu đề Date
Lập trình web Asp.net Đọc file .txt được chọn từ FileUpload trong asp.net 19/6/17