从CSHTML页面重定向 [英] Redirecting from cshtml page

查看:959
本文介绍了从CSHTML页面重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据数据集的结果重定向到其他视图,但是我一直返回到当前所在的页面,无法解决原因.我放入了if语句,该动作被调用,但是一旦我将视图返回到新页面,它将返回我回到当前页面.

I want to redirect to a different view depending on the result of a dataset, but I keep getting returned to the page I am currently on, and can't work out why. I drop into the if statement the action gets called but once i return the view to the new page, it returns me back to the current page.

CSHTML页面

@{
ViewBag.Title = "Search Results";
EnumerableRowCollection<DataRow> custs = ViewBag.Customers;

bool anyRows = custs.Any();
if(anyRows == false)
{


    Html.Action("NoResults","Home");


}
// redirect to no search results view

}

控制器

 public ActionResult NoResults()
    {
       return View("NoResults");

    }

我也无法理解..

@{
ViewBag.Title = "NoResults";
 }

<h2>NoResults</h2>

推荐答案

更改为此:

@{ Response.Redirect("~/HOME/NoResults");}

这篇关于从CSHTML页面重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆