这是我的选择列表ı想要该列表的项目ID,但是ajax代码从不捕获该代码,而ajax序列化捕获,但是ı希望有人可以提供帮助!
<select class="form-control" id="Category" name="Category">
<option >Ara Kategori Ekleyecekseniz</option>
@foreach (var item in Model.CategoryList.Where(x => x.ParentId == 0))
{
<option value="@item.Id">@item.Title</option>
}
</select>
这是我的Ajax代码ı,添加中间类别,但父项id变为0,但我选择了选项,但从未更改……
<script type="text/javascript">
function CategoryAddClick() {
var Category = $("#Category").val();
var ParentId = null;
if (Category != null)
{
ParentId = Category;
}
else
{
var ParentId = 0;
}
var requestData = {
Title: $("#categoryName").val(),
Description: $("#categoryDes").val(),
ParentId: ParentId
};
$.ajax({
url: '/Category/CreateNews',
type: 'POST',
data: JSON.stringify(requestData),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
error: function (xhr) {
alert('Error: ' + xhr.statusText);
},
success: function (result) {
if (result) {
alert("Categori Oluşturma başarılı");
}
},
async: true,
processData: false
});
};
</script>