Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

MVC Validation Problems #1498


User avatar
0
korigoth created

Hey,

Can i know what is the use case for the Validation in MVC to hit before we even get in the controller? (version 10.0.1)

I cannot understand the use case or i cannot see how it should be used ? Is there a place where the error are logged ? Or is there a place where we can get them?

Thx


3 Answer(s)
  • User Avatar
    0
    korigoth created

    bump, still trying to figure out, what is the use case for the validation to hit before the controller.

    Because it cause dead code for MPA in template and it's not userfriendly (cannot use ValidationSummary anymore), so it could be cool if we can get the reason behind the feature and how it is suppose to be used!

    thx

    By the way the DeadCode with this validation is in ControllerBase -> CheckModelState is now useless for MPA

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    We believe that this psedu-code is fairly robotic:

    if(!ModelState.IsValid){ return some error message contains validation errors }

    This is why we automatically handled it.

    • For ajax requests, this approach is very useful.
    • If you are already using client-side validation (using jquery plugins for example), this is also useful since your client actually will never send an invalid data. If you are getting an invalid request, probably a hacker trying to hack your application.

    But if you are returning the same View with validation errors and you don't do client side validation, then you're right. You will want to manually handle it, prepare validation results and return the same view with validation errors included. We don't use this approach much, but it's a common usage by MVC community. I suggest you to use [DisableValidation] attribute to your action or controller in that case. Even you can disable auto validation for all MVC controllers in one place. In your web module's PreInitialize, write this:

    Configuration.Modules.AbpMvc().IsValidationEnabledForControllers = false;
    

    Remember to add "using Abp.Web.Mvc.Configuration;" to your file.

  • User Avatar
    0
    korigoth created

    Ok, thx a lot for your answer and time :)

    It will help to explain this to other while trying to convert them to ASP.Net Boilerplate!