Hi friends ,
I am Trying to Get a result of product list in partial view ,
i want to add a information program to new product add system ,
i want show i.e when i type a word "T" in new product text-box i want to show how meany products is in product table that start a name from "T" ,
or i.e "TE" then its must to show products from name is "TE"
or any word or any name
so please help me to solve this ,
What I have tried:
jqUERY function
$(document).ready(function () {
$("#Product_Name").keyup(function () {
var pnm = $("#Product_Name").val().trim();
alert(pnm);
var Url = "/Product/SerchProd";
$.post(Url, { pnm: pnm }, function (data) {
$.get("/Product/SerchProdList", function (respnse) {
$("#finalprd").html(respnse);
$('.finalprd').SHOW();
return false;
});
});
});
});
partial View()
@model IEnumerable
Product Name :
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.Product_Name)
}
Controller
public JsonResult SerchProd(string pnm)
{
TempData["pnm"] = pnm;
TempData.Keep();
return Json(pnm,JsonRequestBehavior.AllowGet);
}
public PartialViewResult SerchProdList()
{
string pnm = (string)TempData["pnm"];
ViewBag.NameSortParm = String.IsNullOrEmpty(pnm) ? "Name_desc" : "";
var prod = from p in dc.Product_master
select p;
switch (pnm)
{
case "Name_desc":
prod = prod.OrderByDescending(p => p.Product_Name);
break;
}
return PartialView(prod.ToList());
}