要求根据视图中变更项目(CICD)决定变更值(CHV)是text还是dropdownlist
<tr>
<th style="width:20%"><font class="redstar">*</font>变更项目</th>
<td>
@Html.DropDownListFor(model => model.CICD, new SelectList(Dics.GetItems(Dics.DicTypes.itmJczBgxm, true), "CD", "NM", "20"),new { onchange = "MinDate()" })
@Html.ValidationMessageFor(model => model.CICD)
</td>
</tr>
<tr>
<tr>
<th>变更值</th>
<td>
@Html.TextBoxFor(model => model.CHV, new { htmlAttributes = new { } })
@Html.ValidationMessageFor(model => model.CHV)
</td>
</tr>
我的思路是:绑定onblur()方法,使用ajax提交到后台,从后台进行判断。
视图中js语句:
function ChoseInputStyle() {
var a = $('#CICD').val();
$.ajax({
type: "post",
//dataType:"json",
url: '/StchAtt/InputStyle ',
data: {cicd: a },
success: function (data) {
if (data == "jczlb") {
$('#CHV').
//这里不会写
}
});
}
控制器中方法:
public string InputStyle(string cicd)
{
string input = "";
if (cicd != null)
{
if(cicd=="01" || cicd == "02" || cicd == "05" || cicd == "06" || cicd == "07")
{
input = "text";
return input;
}
else if (cicd == "08")
{
//jczlb--"监测站类别"首字母
input = "jczlb";
return input;
}
}
return input;
}
希望各位大神们bang'bang'mang