Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fahad Ayub 71 posts 238 karma points
    Nov 02, 2016 @ 11:19
    Fahad Ayub
    0

    Hi, I have a small form to add Brands in to database. I have created a partial view for form. The form has HtmlAction :

     @Html.ActionLink("Back to List", "Index", "Brand")
    

    But When I click the link I get error message :

    The resource can not be found

    The URL changes to : http://localhost:53298/umbraco/Surface/Brand

    Not sure why it is looking in to umbraco/Surface/.

    Also In my controller I get action to add data in to database , after insertion I would like to redirect the user to Index action using :

     return RedirectToAction("Index");
    

    But I am having same issue getting error "The resource cannot be found".

    The controller code :

     public class BrandController : SurfaceController
        {
            public readonly MongoProductRepoContext MongoContext = new MongoProductRepoContext();
            // GET: Brand
            public ActionResult Index()
            {
                return PartialView("BrandFormView", new PostBrand());
    
            }
            [HttpPost]
            public ActionResult addNewBrand(PostBrand pBrand)
            {
                var brand = new SGBrand(pBrand);
                MongoContext.Brands.InsertOne(brand);
                  return RedirectToAction("Index");
            }
    

    Any idea?

    Thanks

  • Fahad Ayub 71 posts 238 karma points
    Nov 03, 2016 @ 08:26
    Fahad Ayub
    0

    Any help please. Thanks

  • anh tran 2 posts 72 karma points
    Dec 02, 2020 @ 09:20
    anh tran
    0

    Please could you try:

    return RedirectToAction("/Index"); //add slash before Index

    Reference: https://stackoverflow.com/a/42869656/4489400

    Hope this helps.

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Dec 02, 2020 @ 09:35
    Huw Reddick
    0

    /umbraco/Surface is the route that the surfacecontrollers are accessed from.

    Not tried a redirect to action, try a RedirectToCurrentUmbracoPage()

  • anh tran 2 posts 72 karma points
    Dec 02, 2020 @ 09:42
    anh tran
    0

    Hi Huw,

    The problem happens when I create a new item on /CreateNew page and need to redirect to Index page.

    I tried to return RedirectToAction("Index"); but didn't work, tried adding slash before Index and it worked.

    The reference on the link above explains the reason why. Hope it works out for you.

    Thanks, A

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Dec 02, 2020 @ 10:40
    Huw Reddick
    0

    What is the url that would normally get them to the index page? could you not to a simple redirect to that Redirect("umracopageurl") ?

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    Dec 02, 2020 @ 10:48
    Huw Reddick
    0

    you could try

    RedirectToAction("Index","Brand",null) it is one of the overrides, that may work

Please Sign in or register to post replies

Write your reply to:

Draft