모델이있는보기에서 특정 양식을 표시해야합니다. 이 모델은 같다 :보기의 개체 목록을 양식으로 렌더링하는 방법은 무엇입니까?
이 최종 목적은 내가 필요한 것을 채워입니다 :
- 먼저 "정적"부분 :
public class ObjetTotal { public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } public string Numero { get; set; } public string Value { get; set; } }
나는 서로 다른 두 가지 부분으로 양식을 잘라 선택 여기서 사용자는 서로 다른 ObjetsTotal에 대한 공통 값을 입력 할 수 있습니다.
- 둘째로 사용자가 다른 개체에 대해 다른 값을 입력하는 "변수"부분입니다.
최종 목표는 사용자가 모든 객체 ObjetTotal에 대해 동일한 것을 입력해야한다는 것입니다.
그래서 폼의 다른 부분을 나타내는 다른 개체를 만듭니다 (좋은 연습인지 여부는 알 수 없습니다).
MainObjet이있는 정적 부분과 Numbers가있는 가변 부분. 이 두 개체를 하나의 "MainObjet"과 "Numbers"목록이 들어있는 다른 개체 "Mix"에 넣습니다.
public class MainObjet
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
public class Numbers
{
public string Numero { get; set; }
public string Value { get; set; }
}
public class Mix
{
public MainObjet obj { get; set; }
public IEnumerable<Numbers> num { get; set; }
public Mix()
{
obj = new MainObjet();
num = new List<Numbers>();
}
}
그런 다음 모델의 Mix를보기의 두 가지 부분으로 렌더링하려고합니다.
나는이 시도했습니다 :
[HttpPost]
public ActionResult Test(Mix obj)
{
return View();
}
이 어떻게 수행하는 나를 설명 할 수 :
그러나 나는이 ActionResult에서 개체 믹스는 null를 얻을 제출 후
@model App.Models.Mix
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Mix</legend>
<h3>First Properties</h3>
<div>
@Html.TextBoxFor(model => model.obj.Id);
@Html.TextBoxFor(model => model.obj.Name);
@Html.TextBoxFor(model => model.obj.Description);
</div>
<div>
<table>
@for (int i = 0; i < 5; i++)
{
<tr>
<td>
@Html.TextBoxFor(model => model.num[i].Numero)
</td>
<td>
@Html.TextBoxFor(model => model.num[i].Value)
</td>
</tr>
}
</table>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
그거? 나는 틀린 길에 있을지도 모른다.
양식의 디자인을 고려하지 않아도되고 Numbers에 올릴 수있는 올바른 유형을 알지 못합니다. 간단한 목록만으로 충분할 수도 있습니다.
게시 메서드의 매개 변수 이름이 해당 속성 중 하나와 같기 때문에 그것을 다른 것으로 바꾸면 잘 묶일 것입니다. –