Return view with model and query string

I am trying to return to viewing from a controller that has both a query and a model

return View("BillingReport.aspx/?report=" + fc["report_selector"], bilDet); 

but this gives me a runtime error of a page that was not found as it adds .aspx etc. at the end of the url.

RedirectToAction() not able to do this.
Is there a way to do this, or mvc3 restricts us to using either the query string or the model

+4
source share
3 answers

MVC does not support what you are looking for,

But I don’t understand why you want to redirect the URL using ModelValues.

Any redirection is a GET request, so you can build the model and return the View from this action.

View () expects the name and view model associated with it.

Redirect () or RedirectToAction () are used to redirect the URL to another controller / action. Therefore, you cannot pass the model. Even if you try to pass a model, it will add model properties as query parameters.

+2
source

This is why you would like to use the model and query string: querystring allows you to tell the user how to save the URL with status information. The model allows you to transfer a lot of uncompressed data. So, I’m thinking how to do this in MVC 5 (it may not work for older versions, but it probably does):

For presentation, use 2 actions, not 1. use one first to set querystring via RedirectToAction. Use the second action to return the model to the view. And you pass the model from the first action to the second action through the session state. Here is a sample code:

 public ActionResult Index(string email){ Session["stuff"]=Load(email); return RedirectToAction("View1action", new { email = email, color = "red" }); } public ActionResult View1action(string email){ return View("View1",(StuffClass)Session["stuff"]); } 
+1
source

I agree with Manas's answer, and if I were you, I would think about changing the design, if possible.
As a side note, the following are possible:

 TempData["bilDet"] = bilDet; return RedirectToAction(....); // your controller, action etc. 

In this case, you can restore TempData. TempData will be automatically deleted.

But also check: ASP.NET MVC - TempData - good or bad practice

0
source

Source: https://habr.com/ru/post/1398091/


All Articles