How to send model object in Html.RenderAction (MVC3)

后端 未结 3 1815
我寻月下人不归
我寻月下人不归 2020-12-15 04:59

I\'m using MVC3 razor, and I\'m trying to pass an object to a partial view, and it\'s not working.

This works fine without sending the object model to the partial vi

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 05:23

    say you want to pass foo as model, make it first

    public class Foo {
        public string Name { get; set; }
        public int Age { get; set; }
    }
    

    now make an ActionResult

    public ActionResult FooBar(Foo _foo){
        return PartialView(_foo);
    }
    

    call it

    @Html.RenderAction("FooBar", "Controller", new { Name = "John", Age=20 });
    

提交回复
热议问题