Reputation: 190
I don't know what is the reason but my partial view is not displaying, I have tried with other view but problem remains same. I am calling this Partial View using @Ajax.ActionLink, I have put debug points, so it clearly shows that it goes to controller method and successfully return Partial View but it is not displaying.
View(Here I am calling Controller Method):
<li class="nav-menu">@Ajax.ActionLink("Request for Change MobileNumber and EmailId", "ChangeMob", "Admin", new AjaxOptions { UpdateTargetId = "result" })</li>
Controller Method:
public ActionResult ChangeMob()
{
if (Request.IsAjaxRequest())
{
var model = new ChangeMob();
var db = new clubDataContext();
var list2 = (from s in db.tblChanges
select new ChangeMob()
{
id= s.Id,
oldno = s.Old_CNo,
newemail = s.New_Email,
oldemail = s.Old_Email,
mobileoremail = s.Mob_or_Email,
newno = s.New_CNo
}).ToList();
ViewBag.Request = list2;
return PartialView("ChangeMob", model);
}
else
return RedirectToAction("Index", "home");
}
Partial View:
@model IEnumerable<club.Models.ChangeMob>
<h2>Hello there!</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.oldno)
</th>
<th>
@Html.DisplayNameFor(model => model.newno)
</th>
<th>
@Html.DisplayNameFor(model => model.oldemail)
</th>
<th>
@Html.DisplayNameFor(model => model.newemail)
</th>
<th>
@Html.DisplayNameFor(model => model.mobileoremail)
</th>
<th></th>
</tr>
@foreach (var item in ViewBag.Request)
{
<tr>
<td>
@item.oldno
</td>
<td>
@item.newno
</td>
<td>
@item.oldemail
</td>
<td>
@item.newemail
</td>
<td>
@item.mobileoremail
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.id }) |
@Html.ActionLink("Details", "Details", new { id=item.id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.id })
</td>
</tr>
}
</table>
Upvotes: 0
Views: 4278
Reputation: 121
Make your controler return type from public ActionResult ChangeMob() to public PartialViewResult ChangeMob() and check
And make sure that targetID "result" is not set to dispaly:none
Mark it as answered if it work .
Upvotes: 0
Reputation: 596
I see one mistake in your code.
In ChangeMob Action you returns model of ChangeMob type but partial view has another type:
@model IEnumerable<club.Models.ChangeMob>
you should change it to
@model club.Models.ChangeMob
As for partial view displaying. Did you include "jquery.unobtrusive-ajax.min.js" library for using Ajax.ActionLink?
like this:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
Upvotes: 2