D
D
Denis Mashanov2019-07-28 17:29:42
ASP.NET
Denis Mashanov, 2019-07-28 17:29:42

How to specify that a certain Page opens in the specified Route?

Good evening. I can’t figure out how to make sure that the same Page that is not on the default path is displayed with the specified Route. For example, when I go to the path https://localhost:44388/Jvnlp, the application says that it cannot find "View" Jvnlp.cshtml, although it is located on the path ~/Pages/Jvnlp.cshtml

InvalidOperationException: The view 'Jvnlp' was not found. The following locations were searched:
/Views/Views/Jvnlp.cshtml
/Views/Shared/Jvnlp.cshtml
/Pages/Shared/Jvnlp.cshtml

This is the controller
5d3db062344cf970935828.png
This is how I call the action on the controller
<nav>
    <div>
        <ul>
            <li>
                <a asp-area="" asp-controller="Views" asp-action="Jvnlp">ЖВНЛП</a>
            </li>
        </ul>
    </div>
</nav>

Upd: It is necessary to save the Route https://localhost:44388/Jvnlp, but at the same time, in order for this route to open View, which is located along the path in the project ~/Pages/Jvnlp.cshtml

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Mashanov, 2019-07-28
@LoneRay

So far I have found such a solution indicating the full path to the view, which I don’t want to somehow consider as a solution, but what other ways are there, dear experts?

public class HomeController : Controller
{
    public IActionResult Index()
    {
        return View("~/Views/Some/Index.cshtml");
    }
}

To all who later have this question, here is the answer to it. There are a lot of ways to solve this problem at the link below. I used IViewLocationExpander
How to specify the view location in asp.net core m...

D
Denioo, 2019-07-29
@Denioo

I don't fully understand the question, but I'll try to help. In the route, write the default page at startup, on mvc 5 it is done like this, in the route config class:

routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Название твоей стартовой страниц", id = UrlParameter.Optional }

In general, if you do everything right, then the controller name page should be launched, which has the same name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question