Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Use of Shared View in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 43
    Comment on it

    While writing code in MVC there are scenarios where you need to use one view in more than one action .

     

    One way is to create separate view for it that will be a tedious process to do

     

    Another way is to create a common view for multiple action

     

    For doing that you need to write the method or action for it while selecting view you will make it a shared view

     

    public class MenuController : Controller
    {
        [ChildActionOnly]
        public ActionResult Header()
        {
            var model = ... // go to the database and fetch a model
            return View("~/Views/Shared/_Header.cshtml", model);
        }
    }

     

    You will return it wherever you want in your application

     

    You will always create that view inside Shared folder which will make it sharable to other actions

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: