4

Can not find JsonRequestBehavior in aspnet 5

I am trying to implement remote validation demo and it seem like Microsoft.AspNet.Mvc does not contain JsonRequestBehavior enumeration. But it does exist in System.Web.Mvc namespace in previous version of MVC

Model:

public class Person : Entity
    {
        [Required]
        [StringLength(512)]
        [Remote("IsAllowedName", 
                "Validation", 
                ErrorMessage="This name is not allowed!"
               )]
        [Display(Name = "First (and middle) name")]
        public String FirstMidName { get; set; }

View:

...
<input asp-for="FirstMidName"/>
<span asp-validation-for="FirstMidName"></span>
...

Controller:

[HttpGet]
public JsonResult IsAllowedName(string FirstMidName)
{
    if (FirstMidName.ToLower() == "oleg")
    {
        return Json(false, JsonRequestBehavior.AllowGet); 
    }
    return Json(true);
}

Terminal output:

MacBook-Air-Anton:labefmvc antonprudkoglyad$ dnu build 
...
/Users/antonprudkoglyad/Projects/LabEFMVC/LabEFMVC/Controllers/
ValidationController.cs(20,24):
DNXCore,Version=v5.0 error CS0103: The name 'JsonRequestBehavior'
does not exist in the current context

Build failed.
2
  • 1
    Asp 5/MVC 6 is based on a new codebase. It seems that JsonRequestBehaviour has been removed from the new framework (as of beta8). Returning a Json from a controller works by default in GET requests. Commented Oct 26, 2015 at 18:38
  • I did not even find any mention about it at github Commented Oct 28, 2015 at 22:39

1 Answer 1

1

In ASP.NET Core RC1, [Remote] attribute is in the Microsoft.AspNet.Mvc namespace. In ASP.NET Core RC2, [Remote] attribute is in the Microsoft.AspNetCore.Mvc namespace, I believe.

using Microsoft.AspNet.Mvc;

[Remote("IsAllowedName", "Validation", ErrorMessage="This name is not allowed!" )]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.