1
Jquery funktioniert perfekt integer var, aber Fehler für String. Mein Code ist wie folgt.JQuery funktioniert gut mit Integer, aber nicht mit String in MVC 5
@section Scripts {
<script type="text/javascript">
$(function() {
$.getJSON('/Service/ListServiceType', function (result) {
var ddl = $('#ServiceType');
var type = @Model.Type;
ddl.empty();
$(result).each(function() {
$(document.createElement('option'))
.attr('value', this.Type)
.text(this.Type)
.appendTo(ddl);
});
$("#ServiceType").find("option").each(function() {
alert($(this).val())
if ($(this).val() == type) {
$(this).prop("selected", "selected");
}
});
});
$.getJSON('/Category/ListCategory', function (result) {
var ddl = $('#CategoryType');
var id = @Model.CategoryId;
ddl.empty();
$(result).each(function() {
$(document.createElement('option'))
.attr('value', this.Id)
.text(this.Name)
.appendTo(ddl);
});
$("#CategoryType").find("option").each(function() {
if ($(this).val() == id) {
$(this).prop("selected", "selected");
}
});
});
});
</script>
}
Unterer Teil (/ Category/ListCategory) funktioniert einwandfrei, aber nicht der obere. Da ich neu in JQuery und Javascript bin, wäre ein wenig Hilfe sinnvoll.
Was ist das Problem Bereich? Schmale es ein und poste nur relevante Teile – Satpal
Was ist 'Model.Type'? –
Das Problem ist bei Zeile var type = @ Model.Type; Hier ist Typ Zeichenfolge. –