0

I have two view models

public class DataImportViewModel
{
    public WccrViewModel wccrVM { get; set; }
    public string Status                { get; set; }
    public string ValidationResult      { get; set; }
    …
 }

public class WccrViewModel
{
    public double? WccrId  { get; set; }
    public string WccrDesc { get; set; }
}

and my view

@model List<Mass.ViewModels.DataImportViewModel>

@using (Html.BeginForm("Validation", "DataImport", FormMethod.Post))
{ 
<input id="ProcessReshop" type="submit" value="Reshop" />

    for (int i = 0; i < 1; i++)
            {
    <div class="display-field">
        @Html.DisplayFor(model=>model[i].wccrVM.WccrId)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model[i].wccrVM.WccrId)
    </div>
            }

A table (not shown) is populated with the DataImportViewModel. I want to have the WccrViewModel displayed on top of the Table. I want to be able to access the WccrViewModel without the for loop...but it shows as a good example. How can I use wccrVM.WccrId without the for loop? Thanks in advance...cheers

4

1 回答 1

1

另一个包含 DataImportViewModel 和 WccrViewModel 的视图模型类怎么样?

您的视图模型应该针对视图进行定制,如果视图同时调用这两个对象,为什么不创建一个符合其期望的视图模型呢?

于 2012-04-18T07:38:39.617 回答