Reputation: 81
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.
Upvotes: 4
Views: 2680
Reputation: 8592
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!" )]
Upvotes: 1