MVC3 - Passing data beyond the model to Partial view

后端 未结 4 464
天命终不由人
天命终不由人 2021-01-30 13:18

Is there a way to pass a piece of extra data along with a model to a Partial view?

E.G.

@Html.Partial(\"_SomeTable\", (List)ViewBag.Tabl

4条回答
  •  你的背包
    2021-01-30 14:12

    I came across this issue as well. I wanted to have a snippet of code reproduced many times, and did not want to copy paste. The code would vary slightly. After looking at the other answers, I did not want to go that exact route and decided instead to just use a plain Dictionary.

    For example:

    parent.cshtml

    @{
     var args = new Dictionary();
     args["redirectController"] = "Admin";
     args["redirectAction"] = "User";
    }
    @Html.Partial("_childPartial",args)
    

    _childPartial.cshtml

    @model Dictionary
    
    @Model["redirectController"]
    @Model["redirectAction"]

提交回复
热议问题