Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Partial page renders as a new full page

$
0
0

MVC 3 , ajax, c#

My partial view is rendering as a new page instead of replacing the search results table.

Controller:

public class SearchController : Controller
{
//
// GET: /Search/
private myEntities db = new myEntities();
private Repository repo = new Repository();

[HttpGet]
public ActionResult Index()
{
       var model = new List<PersonViewModel>();

       model = repo.GetPeople();

       return View(model);
}




public PartialViewResult _SearchResult(string fname, string lname)
{
      var personResult = repo.GetSearchResult(fname, lname);

      return PartialView("_SearchResult", personResult);
}

}


The view:

<div class="page"><div class="middle-col-comment-mod"><h2>Search Existing Trespassers</h2><div id="search">
                @using (Ajax.BeginForm("_SearchResult", "Search", null, new AjaxOptions { HttpMethod = "Get", InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace, UpdateTargetId = "indexSearchResults" }))
                {<div class="editor-field">   <label>First Name:</label>
                        @Html.TextBox("FirstName")<label style = "margin-left: 15px;">Last Name:</label>
                        @Html.TextBox("LastName", "", new { style = "margin-right: 15px;" })<input type="submit" name="submit" class="skbutton" value="Search" /></div>
                }</div><div id="indexSearchResults" ><table class="data-table"><tr><th>
                                    First Name</th><th>
                                    Last Name</th><th>
                                    Gender</th><th>
                                    City</th><th>
                                    Date of Birth</th><th>
                                    Is a Student?</th><th>
                                    Actions</th></tr>

                        @if (Model.Count() == 0)
                        {
                              <tr><td colspan=7>
                                    There are currently no trespassers in the trespass database.</td></tr>
                        }
                        else
                        {
                        foreach (var item in Model)
                        {<tr><td>
                                    @Html.DisplayFor(modelItem => item.FirstName)</td><td>
                                    @Html.DisplayFor(modelItem => item.LastName)</td><td>
                                    @Html.DisplayFor(modelItem => item.Gender)</td><td>
                                    @Html.DisplayFor(modelItem => item.DOB)</td><td>
                                    @Html.DisplayFor(modelItem => item.School)</td><td>
                                    @Html.DisplayFor(modelItem => item.IsStudent)</td><td>
                                    @Html.ActionLink("Edit", "Edit", new { id = item.PersonId }) |
                                    @Html.ActionLink("Details", "Details", new { id = item.PersonId }) |
                                    @Html.ActionLink("Delete", "Delete", new { id = item.PersonId })</td></tr>
                        }
                        }</table></div></div></div>



And the partial view:

    @model IEnumerable<TrespassTracker.Models.PersonViewModel><table><tr><th>
                First Name</th><th>
                Last Name</th><th>
                Gender</th><th>
                Date of Birth</th><th>
                Is a Student?</th><th>
                Actions</th></tr>

    @if (Model.Count() == 0)
    {
                              <tr><td colspan=7>
                                    There are currently no trespassers in the trespass database - this is a partial view.</td></tr>
    }
    else
    {
        foreach (var item in Model)
        {<tr><td>
                @Html.DisplayFor(modelItem => item.FirstName)</td><td>
                @Html.DisplayFor(modelItem => item.LastName)</td><td>
                @Html.DisplayFor(modelItem => item.Gender)</td><td>
                @Html.DisplayFor(modelItem => item.DOB)</td><td>
                @Html.DisplayFor(modelItem => item.IsStudent)</td><td>
                @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
                @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
                @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })</td></tr>
        }
    }</table><script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>


From my research I found the usual suspect to be the missing link to the jquery script in the partial, but I had that. I checked the network tab on my wed dev tools and found it is being called. What else could the problem be?


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>