0
프로세스를 만들려면 내 MVC 인트라넷에 뷰가 있습니다.내보기로 데이터를 가져와야합니다.
이보기에서 데이터가 채워 져야하는 표가 있습니다.
이
내보기@model TestingTool.ViewModels.ProcessModel
@{
ViewBag.Title = "Create";
}
<h2>
Create</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Process</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Code)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Code)
@Html.ValidationMessageFor(model => model.Code)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<table>
<thead>
<tr>
<th>
Region
</th>
<th>
Owner
</th>
</tr>
</thead>
<tbody>
@if (Model != null)
{
foreach (var item in ViewBag.Regions)
{
<tr>
<td>
@Html.DisplayTextFor(i => item.Name)
</td>
<td>
@Html.DropDownListFor(i => item.User, new SelectList(item.User, "Id", "Name"))
</td>
</tr>
}
}
</tbody>
</table>
<p>
<input type="button" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
입니다 그리고 이것은 나는 ViewBag을 반복하는 것이 가능하다고 생각 내 컨트롤러
//
// GET: /Process/Create
public ActionResult Create()
{
Collection<RegionModel> region = new Collection<RegionModel>();
foreach (var regions in _db.Regions)
{
if (regions.Name != "Europe")
{
RegionModel iRegion = new RegionModel
{
Name = regions.Name,
Id = regions.Id,
User = new Collection<UserModel>()
};
foreach (User user in _db.Users)
{
UserModel iUser = new UserModel { Id = user.Id, Name = user.Name };
iRegion.User.Add(iUser);
}
region.Add(iRegion);
}
}
ViewBag.Regions = region;
return View();
}
,하지만 난이 오류를 얻을
An expression tree may not contain a dynamic operation - mvc
그리고 모델이 미리 채워지는 것이 가능한지 궁금한 또 다른 사항이 있습니다.
재미있는 점은 이전에 시도해 보았지만 제대로 작동한다는 것입니다.보기에서 데이터를 가져옵니다.하지만 '만들기'를 클릭하면 아무 것도 일어나지 않으며 전혀 의미가 없습니다. –
양식 게시를 수락 할 컨트롤러 방법이 있습니까? –
Fro 일부 이상한 이유가 이해가 안 돼요, 지금 작동 중입니다. 저는 Json을 사용하여 컨트롤러에 데이터를 보냈습니다. 그냥 그렇게 작동하기 시작했습니다. Tks도 마찬가지입니다. –