ASP.NET MVC3: Interaction between Partial View and Main View

前端 未结 3 765
难免孤独
难免孤独 2020-12-20 09:55

I have a partial view for contact. Currently the index view shows this partial view for contact details. There is a save button inside the partial view to save the edited d

3条回答
  •  执念已碎
    2020-12-20 10:50

    you'll need to create a new ViewModel to do this. This ViewModel (IndexViewModel.cs) would look something like this (I'm guessing at this):

    public class IndexViewModel
    {
        public int ContactID { get; set; }
        public string ContactName { get; set; }
        public int ContactAge { get; set; }
        public string HoroscopePrediction { get; set; }
    }
    

    you'd then use it in your controller index action (and view):

    @model  MYContactEditPartialViewTEST.IndexViewModel
    

    the idea being that you'd populate the HoroscopePrediction in a join between ContactEntity and AgeHoroscope (or via Linq etc) and thus show each line in the index as a complete object (showing contact and horoscope).

提交回复
热议问题