在我的razor视图中,我有以下if / else语句(它检查是否没有序列号,然后打印下拉列表中没有显示,否则不可用):
@{
var SerialNos = String.Join(", ", Model.SerialNo);
}
@if (SerialNos == "")
{
<div class="col-md-4">
<div class="form-group">
<label>Serial Number</label>
<input name="not available" id="notavailable" class="form-control" value="Not available">
</div>
</div>
}
else
{
<div class="col-md-4">
<div class="form-group">
<label>Serial Number</label>
<select class="form-control" id="ddlSerial">
<option value="@SerialNos">@SerialNos</option>
</select>
</div>
</div>
}
我在脚本中做到了if / else这样,但是我可以做些什么使它在JavaScript中更短吗?
任何人都可以帮助我或为我指明正确的方向!
在此先感谢:)
JavaScript:
<script>
$(document).ready(function () {
var model = {
serialnumber: $("#notavailable").val(),
SelectedSerieText: $("#ddlSerial option:selected").text(),
}
if (model.serialnumber === 'Not available') {
$.ajax({
type: 'POST',
url: '@Url.Action("ProcessRequestRMA", "Account")',
dataType: 'json',
data: {
Serienummer: model.serialnumber
},
success: function (status) {
if (status) {
status.Serienummer = model.serialnumber;
console.log("Send");
}
else {
alert("Something Wrong");
}
},
error: function () {
console.log('something went wrong - debug it!');
}
});
}
else {
$.ajax({
type: 'POST',
url: '@Url.Action("ProcessRequestRMA", "Account")',
dataType: 'json',
data: {
Serienummer: model.SelectedSerieText,
},
success: function (status) {
if (status) {
status.Serienummer = model.SelectedSerieText;
console.log("Send");
}
else {
alert("Something Wrong");
}
},
error: function () {
console.log('something went wrong - debug it!');
}
});
}
});
</script>