Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 208
Jayaraj.K Avatar asked Nov 01 '22 07:11

Jayaraj.K


1 Answers

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");

like image 76
Harish Anchu Avatar answered Dec 01 '22 10:12

Harish Anchu