简体   繁体   中英

Passing model to Html.Action

Using asp.net MVC3, I have a partial view which requires remote validation. As I understand it this means it needs it's own controller, so I'm using Html.Action to call this view and it's controller.

I do however wish to still pass a model to Html.Action, just like I would with Html.Partial. How can I do this?

Html.Action has an overload that expects route values as an object. you could trying passing the model there and model binding will kick in. Your action has to be expecting a parameter of type Model though.

Html.Action("ActionName","ControllerName", Model)

You must pass the model with anonymous classes

    @Html.Action("Menu", "MyController", new { data = Model.Foo.Bar})

    [ChildActionOnly]
    public ActionResult Menu(Bar data )
    {
        return PartialView("Menu", data );
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM