You must Sign In to post a response.
  • Category: ASP.Net MVC

    How to fill partial view in layout page

    I am new in MVC
    I am building an application such that there is a layout page in which at top left side I placed a partial view in that user related details fill ( name , location , photo, designation, role) etc
    that come from 3 different table
    top left there is detail from company table
    at middle left I want to display manu items
    at center I placed render body HTML helper

    now I create new form with using layout master I can fill render body without any problem but how can I fill top left right and menu controls.
    how can I pass model from new created forms to these partial view.
  • #765521
    1. Use Model keyword to pass data to the partial view.
    *Before that you need to hint the view about what type of data you are going to send to the view as follows:

    2. In partial view, you need to inform what type of data you are passing to it, then only you are able to access the properties of class using @Model as follows:
    @model PassingData.Models.Employee
    UserDetail1 : @Model.UserDetail1 '//... name/location/photo/designation/role
    UserDetail2 : @Model.UserDetail2 '//... name/location/photo/designation/role

    You can go through this latest article for more details and techniques about "Different Ways to Pass Data to Partial View":

  • #765524
    thank for your reply
    but I want to pass model only once means

    like in asp.nst if we using master page then at server side I write code at once irrespective of how much content or child page I am using

    but in this scenario if I send model from each an every child pages that not a good thing .

  • #765543
    Hi Javed,

    You can use Razor - Section for this:
    Inside _Layout.cshtml:
    <div id="menu">
    @RenderSection("Menu", required:false)
    & On the pages (Eg. Index.cshtml) you want Menu:
    @section Menu
    @Html.Partial("_Menu", Model.Something)

  • Sign In to post your comments