//
// 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 开发者_如何学JAVAcontains null?You have two possibilities:
Redirect to the
Index
action (sending a 302 status code to the client):return RedirectToAction("Index");
Render the
Index
view (the client keeps the original URL in the address bar, no redirect here):return View("Index", someModelThatTheIndexActionExpects);
If this Index
action is located on another controller you have the possibility to specify this controller name:
return RedirectToAction("Index", "Home");
and:
return View("~/Views/Home/Index.aspx", someModelThatTheIndexActionExpects);
Remark: In your example the txtBoxTitle
argument is declared as System.Int32
, so talking about it being or not being null
just makes absolutely no sense as this is a value type which can never be null
and your if
condition code won't even compile as you have it currently written.
精彩评论