Getting error "Method arguments are not valid! See validationErrors for details " when posting ajax beginform in mvc


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

methods-arguments-are-not-valid-ajax-beginform-min.png

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


Asked by:- Sam
0
: 6793 At:- 4/24/2018 6:01:06 PM
MVC C# asp.net zero boilerplate







1 Answers
profileImage Answered by:- jaya

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.

2
At:- 4/25/2018 11:19:28 AM
Thanks, worked for me :) 0
By : Sam - at :- 5/1/2018 2:16:49 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use