Asp.NET MVC,Jquery and Razor – Cascading dropdown,retrieving partial views,Json send objects,handling errors

There are many blogs and other posts on using jQuery with MVC. You can find individual posts on:

·         How to send objects to an action method via JavaScript.

·         How to retrieve partial views.

·         How to handle errors.

asp.net mvc jquery razor cascading demo

I have written a sample showing how to do all of these together. The sample is written in  MVC 3 using Razor views

The sample demonstrates:

  1. Cascading dropdown ( see the button Populate from action and Cascading drop down)
  2. Populating a table from a Partial View(see the button Add New Employee(jquery call action and render)
  3. How to handle  error from action ( press Save 2 )
  4. How to send id parameters (long) from javascript to action ( press Delete 1 or Delete 2)
  5. How to send objects(Employee) from javascript to action ( press Save 1 or Save 2)

Without further ado,this is the project . Enjoy!

Jquery MVC Razor demo full

PS: If you seems that the code is too hard,here is a more detailed explanation :http://msprogrammer.serviciipeweb.ro/2011/12/05/jquery-ajax-request-and-mvcdetailed/


Posted

in

by

Comments

17 responses to “Asp.NET MVC,Jquery and Razor – Cascading dropdown,retrieving partial views,Json send objects,handling errors”

  1. Rick Anderson/Microsoft Avatar
    Rick Anderson/Microsoft

    Very cool!

  2. Aaron Avatar
    Aaron

    Thanks, I had only seen this done with MVC2

  3. Fabian Avatar
    Fabian

    Hi! Thanks! It was very helpful for me!
    And also i want to know how can i validate a Select created in HTML with the validations in the model?

  4. Nobel Avatar
    Nobel

    Wow! many thanks man, you’re a genius.
    You save a lot of my time research.

  5. Tri Tram Avatar
    Tri Tram

    very good article…thanks you so much..your explanation ‘s very detail and source code so easy to understand with your break point…once again..good article

  6. Krokonoster Avatar

    Thanks Andrei.
    After being absent from MVC a while, your site was just the place to head to catch up on what I forgot.
    Thanks!

    1. Andrei Ignat Avatar
      Andrei Ignat

      Thank you too!

  7. Frank Avatar
    Frank

    great article, By learning from your article, I assume that I could make Master Detail Product Entry form in ASP.net MVC.

    1. Andrei Ignat Avatar
      Andrei Ignat

      Exactly. Just look at how I add a new employee and save an existing employee.

  8. Photobooth Manila Avatar

    Is jQuery can cause a slow loading of a page?

    1. Andrei Ignat Avatar
      Andrei Ignat

      What page? And what does it mean “slow”?

  9. David Avatar
    David

    the way I learned MVC was using the Models, Controllers and View folders – and data access being separate.
    To me, this example is very confusing, since in your Repository, you have ListEmployeesViewModel – there is no model for the controller in the model folder. I have a very hard time distinguishing how the parts all fit together.

    1. Andrei Ignat Avatar
      Andrei Ignat

      Being separate in the same project(MVC) is not enough separate for me.
      Please see detailed explanation here
      http://msprogrammer.serviciipeweb.ro/2011/12/05/jquery-ajax-request-and-mvcdetailed/

  10. tentatively Avatar

    Pretty! This was a really wonderful post.
    Many thanks for supplying these details.

  11. john Avatar
    john

    This is a good exemple for work with MVC with Umbraco. THANKS

  12. Ashutosh Avatar
    Ashutosh

    How to Pass the Parameter in Actionresult type.
    This is return as PartialView.

    1. Andrei Ignat Avatar
      Andrei Ignat

      Did you read my post and download the example?

Leave a Reply

Your email address will not be published. Required fields are marked *