Ajax call is not redirecting to view from controller.

Posted by Farooq_Torus under ASP.NET MVC on 8/22/2017 | Points: 10 | Views : 560 | Status : [Member] | Replies : 1
I am passing productid and productprice by ajax call to the controller and want to display it to he helloPrice page via viewbag. Debugging shows that viewbag in the action method is filled by productid and productprice. but it is not redirecting the view to helloPrice page in order to show the value of viewbag on helloPrice page. Infact nothing happens.
the Action Method passiing the viewbag value to helloPrice view.
public ActionResult helloPrice(int productid,decimal Productprice)
{

String a = "produt ID id " + productid + "and priec" + Productprice;
//string a = "hi";
ViewBag.MyString = "produt ID id " + productid +"yes"+Productprice+"yes";
return View("helloPrice");
}

Ajax request passing the parameter to the controller
$.ajax({
url: '/Products/helloPrice',

data: {
//These two keys should keep consistent with the parameters ( int? ProductId , int? ProductPrice ) in action, including uppercase and lowercase.
productid: productId,
Productprice: discountAmount
},
success: function (data) {
//$('body').empty();
//$('body').append(data);

}
});





Responses

Posted by: Shreedar on: 9/19/2017 [Member] Starter | Points: 25

Up
0
Down
Hi

Remove controller name. Just give action name. It will work for you.

$.ajax({
url: 'helloPrice',

data: {
//These two keys should keep consistent with the parameters ( int? ProductId , int? ProductPrice ) in action, including uppercase and lowercase.
productid: productId,
Productprice: discountAmount
},
success: function (data) {
//$('body').empty();
//$('body').append(data);

}
});

Regards

Sridhar Thota.
www.dotnet-sridhar.blogspot.com

Farooq_Torus, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response