When I am trying to post regular Ajax.BeginForm in my asp.net MVC project (asp.net zero boilerplate project), I am getting this error
Method arguments are not valid! See ValidationErrors for details
Here is the image of the error
My Form is regular one nothing new, C# Controller code is below
[HttpPost]
public JsonResult CreateNew(TenantCommission tc)
{
using (var context = new bwEntities())
{
context.TenantCommissions.Add(tc);
context.SaveChanges();
}
return Json(true);
}
Razor Code
<div class="col-lg-12">
@using (Ajax.BeginForm(CreateNew,
new AjaxOptions { OnSuccess = "OnSuccess", OnFailure = "OnFailure" }))
{
<div class="row">
@Html.AntiForgeryToken()
<div class="col-lg-12">
Commission (%):
<div>
@Html.TextBoxFor(a=>a.Commission,new { @class="onlyDigit"})
</div>
</div>
<!--Code removed for clarity-->
</div>
}
</div>
I am not sure what's the issue, any Idea or link to resolve this issue? Thanks
You can stop getting this error in your ASP.NET zero boilerplate template project by adding this simple line in your ProjectNameWebModule.cs file's PreInitialize method
Configuration.Modules.AbpMvc().IsValidationEnabledForControllers = false;
So, if your project name is ABC file would be like
public class ABCWebModule : AbpModule
{
public override void PreInitialize()
{
// code lines removed
Configuration.Modules.AbpMvc().IsValidationEnabledForControllers = false;
// code lines removed
}
//code removed
}
Build your project and try to submit the form again, should work.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly