MVC: pass parameter to view?

后端 未结 5 432
梦谈多话
梦谈多话 2020-12-14 19:52

MVC newbie question:

I\'m picking up a URL of the form go/{mainnav}/{subnav}, which I\'ve successfully routed to the GoController class, me

5条回答
  •  盖世英雄少女心
    2020-12-14 20:13

    i'm using following approach:

    ViewModel.class:

    public class TitleBodyModel
    {
        public string Title { get; set; }
    
        public string Body { get; set; }
    
        public TitleBodyModel() { Title = Body = ""; }
    
        public TitleBodyModel(string t, string b) { this.Title = t; this.Body = b; }
    }
    

    In the main View:

    @Html.Partial("_TitleBody" , new XXX.Models.TitleBodyModel("title", "body" ))
    

    Then in a partial view:

    @model XXX.Models.TitleBodyModel
    
    
    
    @Model.Title
    @Model.Body

提交回复
热议问题