【发布时间】:2016-03-08 08:56:45
【问题描述】:
我在我的MVC Partial View 中使用IF..ELSE 运算符进行了一些工作,当我在其中使用IF..Else..Operator 时,我的部分视图没有呈现,有人知道我该如何解决这个问题吗?
或
我怎么能以其他方式做到这一点?
错误:“NetworkError:500 内部服务器错误 - http://localhost:50101/TaxRates/EditTaxRates?CountryTaxId=12”
编辑
我的模型不为空,CountryId 也不为空
HTML
<a onclick="editTaxRates(@item.CountryTaxId)"><span class="fa fa-2x fa-edit" style="cursor:pointer; color:black" title='Click to Edit Country'></span></a>
<form id="readIODetail" style="z-index:100">
<div id="divAddCountryRecord" class="modal hide fade " tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false" style="width: 700px; left: 46% !important;">
</div>
</form>
jQuery
function editTaxRates(CountryTaxId) {
var selectedCountryType = $("#selectedCountryType").val();
$.ajax({
type: 'POST',
url: '/TaxRates/EditTaxRates?CountryTaxId=' + CountryTaxId,
success: function (response) {
$("#divAddCountryRecord").empty();
$("#divAddCountryRecord").append(response);
$('#divAddCountryRecord').modal('show');
}
})
}
控制器
public PartialViewResult EditTaxRates(int? CountryTaxId)
{
// conditional code
return PartialView(countryResult);
}
.csHtml(视图)
<div class="modal-body" style="padding-left:10px;overflow-y:auto;">
<div class="row-fluid container">
<div class="span4">
</div>
<div class="row-fluid span12">
<div class="span3">
<p><strong>Country: </strong></p>
</div>
<div class="span5">
@Html.TextBoxFor(m => m.CountryName, new { @readonly = true })
</div>
</div>
<div class="row-fluid span12">
<div class="span3">
<p><strong>Tax-Rate: </strong></p>
</div>
<div class="span5">
@if (Model.CountryId == 1)
{
@Html.TextBoxFor(m => m.TaxRate, new { @id = "C_firstCountry" })
}
else
{
@Html.TextBoxFor(m => m.TaxRate, new { @id = "C_secondCountry" })
}
</div>
</div>
</div>
</div>
感谢您提供宝贵的反馈。
【问题讨论】:
-
而不是
Model =>Model....使用model =>model. -
试试@if (Model.CountryId != null && Model.CountryId == 1)
-
尝试将
@:放在 TextBoxFor 之前。 -
@KartikeyaKhosla,不适用于
model => model -
这是在开玩笑吗 - 3 次你被告知要修复大写 M
Model问题!
标签: c# asp.net-mvc asp.net-mvc-partialview