【问题标题】:How to add a query string from surface controller in umbraco mvc in order to persist model values如何从 umbraco mvc 中的表面控制器添加查询字符串以保留模型值
【发布时间】:2014-01-15 09:19:21
【问题描述】:

如何在 umbraco mvc 中添加来自表面控制器的查询字符串。这是我当前的代码。

最初我写了一个类似

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

这样我可以成功地保存我的 ViewBag 和模型属性值,但我无法使用它添加查询字符串。

对于某些要求,我必须更改返回带有查询字符串的 url 的代码。 我做了如下

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;
}

因此,我在模型中的属性值无法保留,ViewBag 返回空值。

谁能建议我如何通过将值保留在模型和 ViewBag 中来添加查询字符串。

【问题讨论】:

    标签: asp.net-mvc umbraco umbraco6


    【解决方案1】:

    ViewBag 中的数据在重定向时将无法在 View 上使用。因此,您必须在 TempData 中添加消息,该消息将在重定向后在视图中可用,例如 TempData.Add("CustomMessage", "message");

    【讨论】:

      猜你喜欢
      • 2017-03-23
      • 1970-01-01
      • 2023-04-06
      • 2013-07-29
      • 2021-05-13
      • 2013-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多