How to add a query string from surface controller in umbraco mvc in order to persist model values

StackOverflow https://stackoverflow.com/questions/21133332

  •  28-09-2022
  •  | 
  •  

Domanda

How to add a query string from surface controller in umbraco mvc . This is my current code.

Initially I wrote a code like

public ActionResult Registration(RegisterModel model)
{ 
  //Code to insert register details
  ViewBag.Success="Registered Successfully"
  return CurrentUmbracoPage();
}

with this I could successful persist my ViewBag and model properties value but I could not add a query string with it.

For certain requirement I have to change the code that returns a url with querystring. which I did as below

public ActionResult Registration(RegisterModel model)
{ 
    //Code to insert register details
    ViewBag.Success="Registered Successfully"
    pageToRedirect = AppendQueryString("success");
    return new RedirectResult(pageToRedirect);
}
public string AppendQueryString(string queryparam)
{
    var pageToRedirect = new DynamicNode(Node.getCurrentNodeId()).Url;
    pageToRedirect += "?reg=" + queryparam;
    return pageToRedirect;
}

and with this my values of the properties in model could not persist and the ViewBag returned with null value.

Can any one suggest me how to add query string by persisting the values in the model and ViewBag.

È stato utile?

Soluzione

Data in ViewBag will not be available on the View when it redirects. Hence you have to add message in TempData which will be available in the View after the redirect like TempData.Add("CustomMessage", "message");

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top