I have a page "GetData.cshtml
" where I need to fill up some textbox data and send to the controller method. I am using jquery to send data to the controller method.
//GetData.cshtml
$(document).ready(function () {
$('#btn_sbmt_recommendation').click(function () {
$.post("/RegistrationModels/Registration_card",
{
firm_id: $('#id_reg_id').val(),
amount: $('#id_amount').val()
});
console.log("job done....");
});
})
While debugging the app, the controller method is called successfully.
public ActionResult Registration_card(string reg_id, string amount)
{
try
{
// code block
return View(updated_firm);
}
catch (Exception ex) { throw; }
}
As my requirement, I want to display the data in Registration_card.cshtml
page, but it is not redirecting to the page.
The console message console.log("job done....");
in the jquery block is showing. It means the page is again back to GetData.cshtml
. Is it due to using jquery to call controller method?
How can I go to page Registration_card.cshtml
after calling the controller method Registration_card
via jquery.
I also tried with the below code, but it is also not working.
public ActionResult Registration_card(string firm_id, string ward_calani_num, string amount)
{
try
{
// code block
return RedirectToAction("Registration_card", updated_firm);
}
catch (Exception ex) { throw; }
}
2
Answers
If want to redirect page you should use javascript or jquery because when you use jquery then controller not working for redirect.
According to your question, it seems you want to redirect/go to the
Registration_card.cshtm
fromGetData.cshtml
by taking some data from theGetData.cshtml
to theRegistration_card
ActionMethod
which will actually show theRegistration_card.cshtm
.If the above scenario is true, then you do not need to Ajax Post request as your
ActionMethod
isHttpGet
as you do not specify it is asHttpPost
. So the workaround can be something like the below code.