所有
我有以下型号:
public class StateTaxes
{
public StateTaxes()
{
}
public int StateCode{get;set;}
public IList<BlendStateTaxRate> BlendStateTaxes{get;set;}
}
public class BlendStateTaxRate
{
public string BlendName{get;set;}
public int StateCode{get;set;}
public int BlendCode{get;set;}
public decimal TaxRate{get;set;}
}
我的观点包含一个包含状态的下拉列表。下拉列表中的初始条目是 - 选择一个State--,这样当用户导航到/ StateTaxes时。用户会看到一个下拉列表和我的税收列标题。我正在使用JQuery的更改事件来检索用户选择有效状态时与状态相关的税。
我的问题是填充默认视图的最佳方法是什么,该视图仅包含列标题而不包含最终的HTML。我想问题的真正症结在于视图不提供仅创建视图或编辑。
视图如下所示:
<select id="StateList">
<option>--Select a State--</option>
</select>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm())
{ %>
<fieldset>
<legend>State Taxes</legend>
<table>
<thead>
<tr>
<th>
Blend Type
</th>
<th>
Tax Rate
</th>
<th>
Discount Rate
</th>
<th>
ExportFee Rate
</th>
<th>
Inspection Rate
</th>
<th>
PollTax Rate
</th>
<th>
TrustFund Rate
</th>
</tr>
</thead>
<% for (int i = 0; i < Model.BlendStateTaxes.Count; i++)
{ %>
<tr>
<td>
<%= Html.DisplayFor(m => m.BlendStateTaxes[i].BlendName)%>
</td>
<td>
<%= Html.EditorFor(m => m.BlendStateTaxes[i].TaxRate, new { disabled="true" })%>
<%=Html.ValidationMessageFor(m => m.BlendStateTaxes[i].TaxRate)%>
<%=Html.HiddenFor(m => m.BlendStateTaxes[i].BlendCode)%>
</td>
<td>
<%= Html.EditorFor(m => m.BlendStateTaxes[i].DiscountRate, new { disabled = "true" })%>
<%=Html.ValidationMessageFor(m => m.BlendStateTaxes[i].DiscountRate)%>
<%=Html.HiddenFor(m => m.BlendStateTaxes[i].BlendCode)%>
</td>
<td>
<%= Html.EditorFor(m => m.BlendStateTaxes[i].ExportFeeRate, new { disabled = "true" })%>
<%=Html.ValidationMessageFor(m => m.BlendStateTaxes[i].ExportFeeRate)%>
<%=Html.HiddenFor(m => m.BlendStateTaxes[i].BlendCode)%>
</td>
<td>
<%= Html.EditorFor(m => m.BlendStateTaxes[i].InspectionRate, new { disabled = "true" })%>
<%=Html.ValidationMessageFor(m => m.BlendStateTaxes[i].InspectionRate)%>
<%=Html.HiddenFor(m => m.BlendStateTaxes[i].BlendCode)%>
</td>
<td>
<%= Html.EditorFor(m => m.BlendStateTaxes[i].PollTaxRate, new { disabled = "true" })%>
<%=Html.ValidationMessageFor(m => m.BlendStateTaxes[i].PollTaxRate)%>
<%=Html.HiddenFor(m => m.BlendStateTaxes[i].BlendCode)%>
</td>
<td>
<%= Html.EditorFor(m => m.BlendStateTaxes[i].TrustFundRate, new { disabled = "true" })%>
<%=Html.ValidationMessageFor(m => m.BlendStateTaxes[i].TrustFundRate)%>
<%=Html.HiddenFor(m => m.BlendStateTaxes[i].BlendCode)%>
</td>
</tr>
<%} %>
</div>
</table>
</fieldset>
<input id="saveStateTaxes" type="submit" value="Save" />
答案 0 :(得分:0)
根据您的要求,我认为您所做的一切都是正确的,除了在关闭表格标签之前不需要的结束div标签。
如果您可以编写ajax服务来获取记录,我建议您使用客户端模板来绑定表。这样您就可以完全控制视图,并且还可以提高页面性能。