0

i need to render list data in partial page... I have store procedure that is responsible to get list of menus and have master Layoutpage in view--> shared folder--> now i am rendering partial page in masterLayout page but i am not getting any result. I am aware that partial page doesn't go through controller so how i would pass the data in that?

Controller Action

public ActionResult DisplayFunctionsList()
    {
       var myList = F_UOF.GetAllFunctions();

        return View(myList);
    }

Store Procedure Mapping (Model) class

  public class GetAllFunction_SP_Map
{
    public GetAllFunction_SP_Map() { }

    [Key]
    public int Hierarchy_ID { get; set; }

    [Required]
    public int ParentID { get; set; }

    [StringLength(250)]
    [Required]
    public string ParentName { get; set; }

    [Required]
    public int ChildID { get; set; }

    [StringLength(250)]
    [Required]
    public string ChildName { get; set; }

    [StringLength(250)]
    [Required]
    public string Controller { get; set; }

    [StringLength(250)]
    [Required]
    public string Action { get; set; }
}

MasterLayout Page

 @Html.Partial("_DisplayFunctionList_Partial")

Partial Page (_DisplayFunctionList_Partial)

@model IEnumerable<DatabaseLayer.StoreProcedures.StoreProceduresMapping.GetAllFunction_SP_Map>

@foreach(var item in Model)
{
  @item.ParentName 
}
5
  • What do you mean by "partial page doesn't go through controller"? You can have return PartialView(view_name, model); in your controller action. Commented Jan 14, 2014 at 14:24
  • means normally from controller in actionResult method you call view() and pass all data or model in view(model x) Commented Jan 14, 2014 at 14:25
  • What exactly you want to do? Send the object to the Master layout page? Commented Jan 14, 2014 at 14:26
  • @toxic, I call PartialView() all the time :) Commented Jan 14, 2014 at 14:27
  • is PartialView() works in materPage Layout; located in folder> View-->Shared-->MasterLayout Commented Jan 14, 2014 at 14:40

2 Answers 2

4

In this example, since you are calling from the master page, you want to use the Html.RenderAction() method.

@{Html.RenderAction("DisplayFunctionsList", "Controller");}

Edit - the Html.RenderAction must be surrounded by curly braces with the semicolon (';') at the end of the function call. To avoid this, you can use the @Html.Action call, which returns an MvcHtmlString

@Html.Action("DisplayFunctionsList", "Controller")

Also, in using this method, you would need to change your view result slightly because the view you are trying to render is not the name of the action you are calling it from and you appear to be wanting to return a PartialViewResult

public ActionResult DisplayFunctionsList()
    {
       var myList = F_UOF.GetAllFunctions();
        return PartialView("_DisplayFunctionList_Partial", myList);
    }

If you are within a view (not a master page), then you would need to pass the model, assuming the model is of the correct type. If the model for the partial view is a property on your overall view model, then just send the model property instead of the entire model.

*Send Entire Model*
@Html.Partial("_DisplayFunctionList_Partial", Model)

*Send Model Property*
@{Html.Partial("_DisplayFunctionList_Partial", Model.MyList)}
Sign up to request clarification or add additional context in comments.

2 Comments

I have used @Html.RenderAction("DisplayFunctionsList", "DashboardController") as you have mention but i am getting error can't convert void to object
@toxic Err, that one may need to be surrounding by {}, @{Html.RenderAction("DisplayFunctionsList", "DashboardController");} - let me verify
2

The call to @Html.Partial takes a second parameter, which is the model to pass to the partial view. All you need to do is include the list in your View's Model and then pass it along appropriately.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.