1

我需要一个结合两个实体模型的视图。我创建了一个如下所示的类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FSDS.DataModels;

namespace FSDS.WebUX.Models
{
    public partial class ChainandJob
    {
        public ScheduleJobChain chain {get;set;} //this object has 6 properties
        public ScheduleJob job {get;set;} //this object has 8 properties.
    }
}

我使用“创建”脚手架创建了一个新的局部视图。这就是它给我的:

@model FSDS.WebUX.Models.ChainandJob

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>ChainandJob</legend>

        <p>
             <input type="submit" value="Create" />
        </p>
    </fieldset>
 }

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

所有的领域在哪里?

4

2 回答 2

3

您需要自己编写它,例如:

@Html.EditorFor(model => model.ChainandJob.chain.Bla)
@Html.ValidationMessageFor(model => model.ChainandJob.chain.Bla)
@Html.EditorFor(model => model.ChainandJob.job.Bla)
@Html.ValidationMessageFor(model => model.ChainandJob.job.Bla)

等等。

编辑

虽然我不这样做,但您可以让 VSSchedualJobChainScheduleJob. 别忘了之类的@Html.HiddenFor(model => model.ChainandJob.chain.Id

于 2012-08-10T19:05:13.027 回答
2

VS doesn't know your objects. Right after <legend>ChainandJob</legend> try adding

@EditorFor(m => m.chain.ChainProperty)
@ValidationMessageFor(m => m.chain.ChainProperty)

@EditorFor(m => m.job.JobProperty)
@ValidationMessageFor(m => m.job.JobProperty)

and things will be hunky dory :) EditorFor will generate the default output for you, should you need to tweak it - feel free to do so.

于 2012-08-10T19:02:07.007 回答