I have asp.net mvc4 project where i have filter form which based on @Ajax.BeginForm and when I check button in the bottom of the section loaded table with filtered elements where I have one column with dropdowns. And when I select one item of dropdown I want that in the closer columns loaded information based on ma select element, but select isnt into action when I select element. Its have an action when I apply my js script in the Console. My table rendered as partial view.
我有asp.net mvc4项目,我有基于@ Ajax.BeginForm的过滤器表单,当我检查带有过滤元素的部分加载表底部的按钮,其中我有一个带有下拉列的列。当我选择一个下拉项时,我想在更接近的列中加载基于ma select元素的信息,但是当我选择元素时选择isnt into action。当我在控制台中应用我的js脚本时,它有一个动作。我的表呈现为局部视图。
<div class="col-md-2">
<select id="UniversityProgramId" name="UniversityProgramId">
<option disabled="disabled">Select program</option>
@foreach(var program in item.Program)
{
<option value="@program.ProgramId">@program.ProgramName</option>
}
</select>
</div>
$(document).ready(function () {
$(function () {
$('#UniversityProgramId').change(function () {
$.getJSON('/Filter/ProgramCost/' + $('#UniversityProgramId').val(), function (data) {
var items = data;
$('#ProgramPrice').html(items);
});
});
});
});
Update, here is my JSonResult view inside filter controller
更新,这是我的过滤器控制器内的JSonResult视图
public JsonResult ProgramCost(int Id)
{
var model = _repo.GetPrograms().Where(x => x.ProgramId == Id).Select(x => x.Price);
return Json(model, JsonRequestBehavior.AllowGet);
}
1 个解决方案
#1
0
You are calling .getJSON, but then placing the results into the HTML of the ProgramPrice.
您正在调用.getJSON,但随后将结果放入ProgramPrice的HTML中。
If /Filter/ProgramCost/' + $('#UniversityProgramId').val()
is returning JSON, then you'll need to traverse each element and create the HTML. I doubt you can just set the HTML using JSON values.
如果/ Filter / ProgramCost /'+ $('#UniversityProgramId')。val()返回JSON,那么你需要遍历每个元素并创建HTML。我怀疑你可以使用JSON值设置HTML。
#1
0
You are calling .getJSON, but then placing the results into the HTML of the ProgramPrice.
您正在调用.getJSON,但随后将结果放入ProgramPrice的HTML中。
If /Filter/ProgramCost/' + $('#UniversityProgramId').val()
is returning JSON, then you'll need to traverse each element and create the HTML. I doubt you can just set the HTML using JSON values.
如果/ Filter / ProgramCost /'+ $('#UniversityProgramId')。val()返回JSON,那么你需要遍历每个元素并创建HTML。我怀疑你可以使用JSON值设置HTML。