return Json(Url.Action("MyReport", "Account")); is not invoking the get method MyReport
The
Url.Action(string,string) method returns the fully qualified URL to an action method, which means the check action will return you a string which is the url of the MyReport action in Account controller(in the "else" condition).
Member
40 Points
158 Posts
not invoking get method
Mar 18, 2020 05:26 AM|shijostephen|LINK
Hi,
I am unable to load data in my current view, for this i called a get action method but not invoking
return Json(Url.Action("MyReport", "Account")); is not invoking the get method MyReport
Thanks & Regards
Shijo
All-Star
53131 Points
23682 Posts
Re: not invoking get method
Mar 18, 2020 10:41 AM|mgebhard|LINK
I think you want to redirect not return JSON.
https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.controller.redirecttoaction?view=aspnet-mvc-5.2#System_Web_Mvc_Controller_RedirectToAction_System_String_System_String_
Contributor
3140 Points
983 Posts
Re: not invoking get method
Mar 19, 2020 02:51 AM|Yang Shen|LINK
Hi shijostephen,
The Url.Action(string,string) method returns the fully qualified URL to an action method, which means the check action will return you a string which is the url of the MyReport action in Account controller(in the "else" condition).
To load data in the current view, the RedirectToAction(String, String) method shall be used.
You can refer to below demo which built based on your provided code and it shows MyReport returned view in the current view:
Trigger.cshtml:
actions in controller:
public ActionResult TriggerDemo() { return View(); } [HttpPost] public ActionResult check(string UserName, string Password) { int a = 1; if (a > 2) { return View(); } else { //return Json( Url.Action("MyReport", "Demo") ); return RedirectToAction("MyReport", "Demo"); } } [HttpGet] public ActionResult MyReport() { TestItem item = new TestItem() { id = 1,name="item1" }; return View("MyReport", item); }
TestItem model:
The result:
The result when you return the json(url.action(string,string)):
Best Regard,
Yang Shen
Member
40 Points
158 Posts
Re: not invoking get method
Mar 19, 2020 04:33 AM|shijostephen|LINK
Hi,
RedirectToAction redirects to the Get Method, but it is not rendering the changed view with new model data..
Network tab has the response, but it is not rendering in the browser
Thanks & Regards
Shijo
Contributor
3140 Points
983 Posts
Re: not invoking get method
Mar 19, 2020 05:47 AM|Yang Shen|LINK
Hi shijostephen,
You want to rerender the current page with the reponse you get from the check action?
If so, you can refer to How to replace the entire html webpage with ajax response?
Best Regard,
Yang Shen