0

I want to send "name" as a parameter to controller, but controller is not receiving the parameter

$(document).ready(function () {
  $("#btn1").click(function () {
    var name = $("#search").val();
    //name = "ali";
    alert(name);
    $.post("/Status/searchByName", { typeId: name }, function (data) {
      document.write(data);
      $.each(data, function (key, value) {
        //document.write(data,value);
        // Here you can iterate data one by one and process it.
      });
    }, "text");           
  });
});

here is action method

[HttpPost] 
public JsonResult searchByName(string name)
{           
  dbCRMEntities dbx = new dbCRMEntities();         
  var names = dbx.CONTACTS.Where(chk => name == chk.NAME);
  return this.Json(names, JsonRequestBehavior.AllowGet);                
}

this action method is receiving only null

Umair
  • 65
  • 7

1 Answers1

7

Your passing { typeId: name } but you method expects a parameter named name

Change the parameter to

public JsonResult searchByName(string typeId) 

or alternatively adjust the script to

$.post("/Status/searchByName", { name: name }, function (data) {