进入索引页?
//
// Post: /Search/Alternativ1/txtBoxTitle)
[HttpPost]
public ActionResult Alternativ1(int txtBoxTitle)
{
SokningMedAlternativ1 test= new SokningMedAlternativ1();
if (txtBoxTitel != null)
{
var codeModel = test.FilteraBokLista(txtBoxTitel);
}
return View(codeModel);
}
问题:
如果 txtBoxTitle 为空,我无法找到返回索引页(第一次进入网站时的第一页)查看的解决方案。
我的要求:
如果txtBoxTitle包含null,我该如何自动进入我的索引页面视图?
//
// Post: /Search/Alternativ1/txtBoxTitle)
[HttpPost]
public ActionResult Alternativ1(int txtBoxTitle)
{
SokningMedAlternativ1 test= new SokningMedAlternativ1();
if (txtBoxTitel != null)
{
var codeModel = test.FilteraBokLista(txtBoxTitel);
}
return View(codeModel);
}
Problem:
I have problem to find a solution to go back to my index page (first page when entering a website for the first time) view if txtBoxTitle has null.
My request:
How shall I enter to my index page view automatically if txtBoxTitle contains null?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有两种可能性:
重定向到
Index
操作(向客户端发送 302 状态代码):渲染
Index
视图(客户端保留地址栏中的原始 URL,此处没有重定向):如果此
Index
操作位于另一个控制器,您可以指定此控制器名称:和:
备注:在您的示例中,
txtBoxTitle
参数声明为System.Int32
,所以谈论它是否为null
绝对不会这是一个永远不可能为 null 的值类型,并且您的 if 条件代码甚至不会像您当前编写的那样进行编译。You have two possibilities:
Redirect to the
Index
action (sending a 302 status code to the client):Render the
Index
view (the client keeps the original URL in the address bar, no redirect here):If this
Index
action is located on another controller you have the possibility to specify this controller name:and:
Remark: In your example the
txtBoxTitle
argument is declared asSystem.Int32
, so talking about it being or not beingnull
just makes absolutely no sense as this is a value type which can never benull
and yourif
condition code won't even compile as you have it currently written.