0

I have an ASP.NET MVC4 Internet application, I wanted to use two Models in a single view but it seems it is not easy as i just wished. I am a MVC newbie by the way. Here is my First Model Code

    public class FirstCmOutput
{
    public int FirstCmOutputId { get; set; }
    [Required]
    public string Name { get; set; }
    public string Intervention { get; set; }
    public string Indicator { get; set; }
    public string UseOfOutput { get; set; }
    public string UserOfOutput { get; set; }
    public DateTime PlanningFrom { get; set; }
    public DateTime PlanningTo { get; set; }
    public DateTime DateOfPlanning { get; set; }
    public string City { get; set; }


    public virtual ICollection<FirstCmActivity> Activity { get; set; }
}

Here is My Second Model.

    public class FirstCmActivity
{
    public int FirstCmActivityId { get; set; }
    public string Name { get; set; }
    public DateTime PlannedStartDate { get; set; }
    public DateTime PlannedEndDate { get; set; }
    public DateTime OngoingStartDate { get; set; }
    public DateTime OngoingEndDate { get; set; }
    public DateTime FinishedDate { get; set; }
    public string GizResponsible { get; set; }
    public string PartnerResponsible { get; set; }
    public string swAfghanSide { get; set; }
    public string swGiz { get; set; }
    public string swRodeco { get; set; }
    public string swExtern { get; set; }
    public string EquipmentNeeds { get; set; }
    public string EquipmentExist { get; set; }
    public string MileStone { get; set; }

    public int FirstCmOutputId { get; set; }


    public virtual FirstCmOutput Output { get; set; }
}

I have added another Model called View Model and injected above models just like below.

public class ViewModel
{
    public IEnumerable<FirstCmOutput> FirstOutput { get; set; }
    public IEnumerable<FirstCmActivity> FirstActivity { get; set; }
}

and finally here is my View Code, it worth to mention that i am using scaffolding.

<div class="editor-label">
@Html.LabelFor(model => model.FirstOutput.Name)
Naser Dostdar
  • 61
  • 1
  • 2
  • 12
  • 1
    what's the question ? show me your view – Cristi Pufu Jul 28 '14 at 15:20
  • 1
    possible duplicate of [Multiple models in a view](http://stackoverflow.com/questions/4764011/multiple-models-in-a-view) – PaulBinder Jul 28 '14 at 15:23
  • unable to post view any help it ask me to format the code properly i don't know how to do it. – Naser Dostdar Jul 28 '14 at 15:25
  • In your view you you treat `FirstOutput` property as type of `FirstCmOutput` in your view model it is `IEnumerable` so the question is what you wan to achive? Should it be `IEnumerable` or not? – py3r3str Jul 29 '14 at 14:36

0 Answers0