[英]Partial View not showing(ASP.NET MVC)
I have Partial View 我有局部视图
Here is code 这是代码
@model IEnumerable<SmartSolutions.Models.QuestionBlock>
@foreach (var item in Model) {
<div>
@Html.DisplayFor(modelItem => item.Question1)
</div>
}
Here code for controller 此处为控制器代码
public ActionResult Recording(int id)
{
/*var items = db.QuestionBlocks
.Where(x => x.Interview_Id == id)
.Select(x => x).ToList();*/
ApplicationDbContext db = new ApplicationDbContext();
return View();
}
public ActionResult QuestionBlock(int id) {
ApplicationDbContext db = new ApplicationDbContext();
var questionblocks = db.QuestionBlocks.Take(id);
return PartialView(questionblocks);
}
Here is code of View where I try to show PartialView 这是View的代码,我尝试显示PartialView
<div class="inner-div4" style="background: #ffffff">
<div class="counter-one">
3/10
</div>
<div class="right-welcome-div2-borderless" style="background: #e5e5e5">
<div class="timer-div-one" id="countdown" style="height: 20px; width: 20px;">
</div>
<div class="counter-div">
</div>
<p>@Html.Label("Show", htmlAttributes: new { @class = "showList", @style= "cursor:pointer;", data_rows = 1 })</p>
<div id="questions">
</div>
Here is AJAX call 这是AJAX通话
<script>
$('.showList').click(function (e) {
var rows_num = this.getAttribute("data-rows");
$.ajax({
type: "GET",
url: "/interwier/QuestionBlock",
data: { id: rows_num },
sucess: function (data) {
$("#questions").html(data);
},
error: function () {
alert("Smth wrong in controller");
}
});
});
My problem in that < when I click <p>@Html.Label("Show", htmlAttributes: new { @class = "showList", @style= "cursor:pointer;", data_rows = 1 })</p>
I see in Network console data, but not see on View. 我的问题在于<当我单击
<p>@Html.Label("Show", htmlAttributes: new { @class = "showList", @style= "cursor:pointer;", data_rows = 1 })</p>
我在网络控制台中看到数据,但在View上看不到。
You have a typo in your AJAX code: sucess
instead of success
. 您的AJAX代码中有错别字:
sucess
而不是success
。 Essentially, you have no success
method at the moment, so nothing happens with the returned response. 本质上,您目前没有
success
方法,因此返回的响应不会发生任何事情。
I think change parameter name data_rows to id . 我认为将参数名称data_rows更改为id 。 so please try it.
所以请尝试一下。
And simple changes in your method. 并对方法进行简单的更改。
public ActionResult QuestionBlock(int id) {
ApplicationDbContext db = new ApplicationDbContext();
var questionblocks = db.QuestionBlocks.Take(id);
return PartialView("Name_Of_PartialView",questionblocks);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.