저는 MVC에 매우 익숙합니다. 제 질문에 답해주십시오. 다음 구조로 작업해야합니다. 다음 시설, 주소 및 모델이 있습니다.Partialview는 sortedlist에 대한 모델을 반환하지 않습니다.
[HttpPost]
public ActionResult FacilityCreate(AppFacility objFacility)
{
facilityManager = new Manager.AppFacilityManager();
if (facilityManager.InsertAppFacility(objFacility))
{
return RedirectToAction("FacilityInfo", new { id = objFacility.FacilityID });
}
return View((AppFacility)Session["FacilityObject"]);
}
보기 : FacilityCreate
@model Model.CORE.BO.AppFacility
<table width="100%" align="center" border="0" class="SectionTables">
<tr>
<td class="SubtitleHeader">
Facility
</td>
</tr>
<tr>
<td class="SubtitleHeader1">
Enter Facility Information
</td>
</tr>
<tr>
<td align="center">
@Html.Partial(p_CreateEditAppFacility, Model)
</td>
</tr>
부분보기 시설이 주소의 SortedList를 포함, 나는 명확성의 속성의 수,
public class AppFacility
{
public AppFacility()
{
this.Addresses = new SortedList<string, AppAddress>();
}
public SortedList<string, AppAddress> Addresses { get; set; }
[DisplayNameAttribute("Facility ID")]
public int FacilityID { get; set; }
[Required(ErrorMessage = "Facility Name is a required field")]
[DisplayNameAttribute("Facility Name")]
public string FacilityName { get; set; }
[DisplayNameAttribute("Doing Business As")]
public string Dba { get; set; }
[DisplayNameAttribute("Nbr. Of Employees")]
public int NbrOfEmployees { get; set; }
}
public class AppAddress
{
[DisplayNameAttribute("City")]
public string City { get; set; }
[DisplayNameAttribute("State")]
public string State { get; set; }
[DisplayNameAttribute("Street Name")]
public string StreetName { get; set; }
}
컨트롤러를 감소 : p_CreateEditAppFacility : 여기에는 p_CreateEditAddress 부분보기도 포함됩니다.
@model Model.CORE.BO.AppFacility
@using (Html.BeginForm("FacilityCreate", "Form", FormMethod.Post,
new { id = "saveForm", name = "saveForm" }))
{
@Html.ValidationSummary(true)
<div class="main">
<fieldset>
<legend>Operator Information</legend>
<div class="editor-label">
@Html.Label("Facility Name (Business Name of Operator to Appear): ")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FacilityName)
@Html.ValidationMessageFor(model => model.FacilityName)
</div>
<div class="editor-label">
@Html.Label("Owner's Business Name (If different from Business Name of Operator): ")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Dba)
@Html.ValidationMessageFor(model => model.Dba)
</div>
<div class="editor-label">
@Html.Label("No of Employees:")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.NbrOfEmployees)
@Html.ValidationMessageFor(model => model.NbrOfEmployees)
</div>
</fieldset>
<fieldset>
<legend>Address Information</legend>
@{
int i = 0;
foreach (KeyValuePair<string, Model.CORE.BO.AppAddress> addressRow in Model.Addresses)
{
<div class="editor-field">
@Html.Partial(p_CreateEditAddress, addressRow.Value, new ViewDataDictionary(Html.ViewDataContainer.ViewData) { TemplateInfo = new System.Web.Mvc.TemplateInfo { HtmlFieldPrefix = string.Format("objFacility.Addresses[{0}]", i) } })
</div>
i++;
}
}
</fieldset>
<p>
<input id="SaveFacility" name="SaveInfo" type="submit" value="Save Information" />
</p>
</div>
은}
PartialView : 항상 널 (null) p_CreateEditAddress
@model Model.CORE.BO.AppAddress
@Html.ValidationSummary(true)
<div class="editor-label">
@Html.LabelFor(model => model.StreetName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.StreetName)
@Html.ValidationMessageFor(model => model.StreetName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.City)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.City)
@Html.ValidationMessageFor(model => model.City)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.State)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.State)
@Html.ValidationMessageFor(model => model.State)
</div>
내 질문은 컨트롤러에 objFacility.Addresses이 값이 모델 AppAddress에 입력하지 않는다는 것입니다이다. AppFacility가 생성됩니다. 있는 HTML이 뒤에 p_CreateEditAddress
<div class="editor-field">
<input class="text-box single-line"
id="objFacility_Addresses_0__StreetName"
name="objFacility.Addresses[0].StreetName" type="text" value="" />
<span class="field-validation-valid"
data-valmsg-for="objFacility.Addresses[0].StreetName" data-valmsg-replace="true"></span>
</div>
에 대해 다음과 같습니다 도와주세요.
어떤 이유로 당신이 objFacility 접두사를 설정하고 있는가 :
이가 (I 라인 읽기 쉽에서 휴식을 넣어) 시도? – VJAI