2010-03-10 4 views
5

제품 제품 아이디 제품 이름동일한 뷰에서 일대 다 관계 엔티티를 업데이트하는 방법은 무엇입니까?

공급 나는 새로운 제품을 만들 때, 나는에뿐만 아니라 공급 업체를 입력 할 수있는 텍스트 상자를 갖고 싶어 공급 업체 ID 제품 ID SupplierName

같은 견해. 이것은 좋은 습관입니까? 제품에는 여러 공급 업체가있을 수 있으므로 동일한보기에서 공급 업체 레코드를 더 추가 할 수 있기를 원합니다. 어떻게해야합니까??

나는 aspx 페이지에 무엇을 넣을지 고민 중입니까?

나는 <% = Html.TextBoxFor (모델 => model.Supplier) %> 내가 System.Data.Objects.DataClasses.EntityCollection`1 [MyProject.Mvc.Models.Supplier]와 텍스트 상자를보고 뭔가를 넣어 경우 그 안에.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<MyProject.Mvc.Models.ProductFormViewModel>" %> 
<%= Html.ValidationSummary("Please correct the errors and try again.") %> 
<% using (Html.BeginForm()) {%> 
<fieldset> 
<legend>Fields</legend> 

<div class="editor-label"> 
    <%= Html.LabelFor(model => model.Product.ProductId) %> 
</div> 
<div class="editor-field"> 
    <%= Html.TextBoxFor(model => model.Product.ProductId) %> 
    <%= Html.ValidationMessageFor(model => model.Product.ProductId) %> 
</div> 

<div class="editor-label"> 
    <%= Html.LabelFor(model => model.Product.ProductName) %> 
</div> 
<div class="editor-field"> 
    <%= Html.TextBoxFor(model => model.Product.ProductName) %> 
    <%= Html.ValidationMessageFor(model => model.Product.ProductName) %> 
</div> 

<div class="editor-label"> 
    <%= Html.LabelFor(model => model.Product.Description) %> 
</div> 
<div class="editor-field"> 
    <%= Html.TextBoxFor(model => model.Product.Description) %> 
    <%= Html.ValidationMessageFor(model => model.Product.Description) %> 
</div>    
<p> 
    <input type="submit" value="Create" /> 
</p> 
</fieldset> 

<% } %> 

ProductViewModel

public class ProductFormViewModel 
{ 
    public Product Product{ get; private set; } 
    public IEnumerable<Supplier> Supplier { get; private set; } 

    public ProductFormViewModel() 
    { 
     Product = new Product(); 
    } 

    public ProductFormViewModel(Product product) 
    { 
     Product = product; 
     Supplier = product.Supplier; 
    } 
} 
+0

간단히 말해, 신제품을 추가하고 제품 생성보기에서 첫 번째 공급 업체를 추가하려고합니다. 그러면 제품의 편집보기에서 추가 공급 업체를 추가 할 수 있습니다. 편집보기에서 무언가를 클릭하면 새 공급자를 입력 할 수있는 텍스트 상자가 표시되고 제출하면 제품의 공급자가 업데이트됩니다. 제품과 공급 업체는 일대 다 관계를 맺고 있습니다. – Picflight

+0

아! 나는 MVC 주위에 머리를 감싸는 그런 거친 시간을 보내고있다. 여러 번 나는 Web Forms에서이 작업을 수행하는 것을 생각했지만 포기하고 싶지는 않습니다. – Picflight

답변

관련 문제