Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

navigate between pages #3924


User avatar
0
avanekar02 created

Hello

i want to navigate from 1 cshtml page to another inside app/tenant/view/store/page1.cshtml to app/tenant/views/store/page2.cshtml from a href tag

can you please show me how it is done

regards Anwar


6 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    It's not clear what you mean. Views (.cshtml) are accessed through controller actions (a.k.a. methods). Your question seems to be asking about how ASP.NET works in general and not about this framework.


    If you have 2 views, then you need one action for each:

    public ViewResult Page1()
    {
        return View();
    }
    
    public ViewResult Page2()
    {
        return View();
    }
    

    and Page1.cshtml will contain:

    <a asp-action="Page2">Go to Page 2</a>
    

    If you mean pagination, i.e. display different items using the same view template, then you should accept one action:

    public ViewResult Page(int num)
    {
        return View(num);
    }
    

    and Page.cshtml will contain:

    @model int
    <h1>This is page @Model.</h1>
    

    which can be accessed by app/tenant/view/store/page?num=1 and app/tenant/view/store/page?num=2.

  • User Avatar
    0
    avanekar02 created

    Hi aaron

    thank you for your reply, what i mean is if you look at the path there are 2 pages both sitting under app/tenant/views/page1.cshtml and page2.cshtml what i wanted was navigate from page1 to page2 using url action.

    Regards Anwar

  • User Avatar
    0
    aaron created
    Support Team

    Hi Anwar, if I look where?

  • User Avatar
    0
    avanekar02 created

    under web project App |_________Tenants |_________________Views |____________MyFolder |___________________Page1.cshtml |____________________Page2.cshtml

    page1.cshtml is already defined in the menu with all permissions, page 2 is not a link in the menu so i want to call page2 from page1 using a href .

    Hope that helps

    Regards Anwar

  • User Avatar
    0
    aaron created
    Support Team

    That doesn't look valid. Can you share an actual project with those files?

  • User Avatar
    0
    avanekar02 created

    Thanks aaron,

    Resolved it .