0

when I am posting the form back using Ajax.ActionLink() I am getting null values for all the properties. I have also tried the same using @ajax.beginform(). But i ended up with an error "Unexpected token u" in the console. Please help.

My class goes like this

public class Search
{
    public string SearchText { get; set; }
    public int ContinentId { get; set; }
    public string City { get; set; }
}

My View goes like this

@model MvcApplication5.Models.BusinessLogic.Search
@{
ViewBag.Title = "Index";
var continetList = (SelectList)ViewBag.TargetContinentName;
var infoTypesList = (List<SelectListItem>)ViewBag.Infotype;
}
@Html.TextBoxFor(m => m.SearchText)<br/>
 @Ajax.ActionLink("Search", "Search", "Home", new AjaxOptions{    HttpMethod = "POST",    UpdateTargetId = "submitId",  InsertionMode = InsertionMode.Replace,
LoadingElementId = "loadingId"})
</div>

My controller goes like this

//POST:/Home/
    [HttpPost]
    public PartialViewResult Search(Search search, int? page)
    {
        //Code goes here
        //Here the object search is giving me null values for all the properties
        return PartialView("_Search",listInfo);
    }
Swagat Swain
  • 495
  • 1
  • 4
  • 22

1 Answers1

0

you have to use Ajax.BeginForm like this:

@model MvcApplication5.Models.BusinessLogic.Search
@{
ViewBag.Title = "Index";
var continetList = (SelectList)ViewBag.TargetContinentName;
var infoTypesList = (List<SelectListItem>)ViewBag.Infotype;
}

 @using (Ajax.BeginForm("Search", "Home", 
 new AjaxOptions
{
    HttpMethod = "POST",
    UpdateTargetId = "submitId",
    InsertionMode = InsertionMode.Replace,
    LoadingElementId = "loadingId"
}, 
new  { page = 1}))
{
@Html.TextBoxFor(m => m.SearchText)
@Html.HiddenFor(m=>m.ContinentId)
@Html.HiddenFor(m=>m.City)

<input type="submit" value="Search" name="Search"/>
}
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160