开发者

Entering to index page?

开发者 https://www.devze.com 2023-02-04 04:53 出处:网络
// // Post: /Search/Alternativ1/txtBoxTitle) [HttpPost] public ActionResult Alternativ1(int txtBoxTitle)
    //
    // 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:

  1. Redirect to the Index action (sending a 302 status code to the client):

    return RedirectToAction("Index");
    
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号