[英]unable to render partial view in asp.net mvc using ajax?
Problem is : I do have Index.cshtml as 问题是:我确实有Index.cshtml作为
@{
ViewBag.Title = "Search";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="@Url.Content("../../Scripts/jquery.unobtrusive-ajax.min.js") type="text/javascript"></script>
<h2>Answer's are </h2>
<div id="result">
@Ajax.ActionLink("Search Wiki",
"WikiAns",
new AjaxOptions{
UpdateTargetId = "result",
InsertionMode=InsertionMode.Replace,
HttpMethod="GET",
LoadingElementId="progress"
})
</div>
<div id="progress" style="display: none">
<img src="@Url.Content("../../Content/Images/ajax-loader.gif")" alt="loader" />
</div>
Now i do have partial view model _WikiAns : 现在我有局部视图模型_WikiAns :
@model IEnumerable<Questions.Models.WikiAnsClass>
<h2>Our Links</h2>
<table>
@foreach (var item in Model) {
<tr>
<td>
<a href="@item.url" target="_blank">@item.content</a>
</td>
</tr>
}
</table>
Now using above i want is that...on clicking Search Wiki action link, id="result" get all partial view rendered in it. 现在在上面使用我想要的是...在单击“ 搜索Wiki”操作链接时,id =“ result”使所有局部视图呈现在其中。 But its not happening.
但是它没有发生。 Instead of its going to a page "
localhost:80/Search/WikiAns
" and showing the result there. 而不是转到页面“
localhost:80/Search/WikiAns
”并在那里显示结果。 but i want to it to stay at localhost:80/Search
and replace its "result" id. 但我希望它保持在
localhost:80/Search
并替换其“结果” ID。 but its not working this way. 但它不能这样工作。
Here is my action called WikiAns
这是我的动作,称为
WikiAns
public ActionResult WikiAns()
{
//Code to follow...
var wikians = //code to follow
return PartialView("_wikiAns", wikians);
}
What's the problem ? 有什么问题 ?
Also how can i implement this Ajax GIF loader...i mean showing it while action gets executed. 还有我如何实现这个Ajax GIF加载器...我的意思是在执行动作时显示它。 ?
?
Please suggest 请建议
Thanks 谢谢
@Pbirkoff may be right about this but you can go through my post of very easy to implement demo of your scenario and build it up from there. @Pbirkoff可能对此是正确的,但是您可以阅读我的非常容易实现的场景演示文章,然后从那里开始进行构建。
http://mazharkaunain.blogspot.com/2011/05/aspnet-mvc-razor-render-partial-view.html http://mazharkaunain.blogspot.com/2011/05/aspnet-mvc-razor-render-partial-view.html
http://mazharkaunain.blogspot.com/2011/04/aspnet-mvc-render-partial-view-using.html http://mazharkaunain.blogspot.com/2011/04/aspnet-mvc-render-partial-view-using.html
您需要在页面或布局中包括Microsoft Ajax脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.