I am trying to create two MVC applications, and in first application created one view and compiled the application, and in the second application i have added the dll of the first application.
in the routeconfig.cs file added the below line.
"Structure of First application"
Application1
Controller
Home(Actionmethod is Home)
View
Home.cshtml
Application2: references:Application1
_layout.cshtml.
trying to access url: localhost/Home
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "TestApp.Controllers" }
and i am trying to call the view from the first application, but it is not able to find the view from the first application, can any body tell me any other configurations do i need to add to access the view of first application.
Thanks in advance.
Please explain why you have them in two separate mvc applications.
app 1.
controller
view
model
app 2.
controller
view
model
Im not sure if view are compiled into the .dll if they are. Then how are you accessing them?
Also you need to register your search locations for your views... I assume your are using the razor engine.
http://theshravan.net/blog/configure-the-views-search-locations-in-asp-net-mvc/
Can I specify a custom location to "search for views" in ASP.NET MVC?
Basically you need to register the search locations for your views the default is
App
Views
[ViewName]Controller
I have a strong feeling the app which references the .dll [App1]
Has nothing in it to tell it to look in App2 for views as well.
Hope this makes sense ;-)
Try creating Area in your project and create required controller and views instead of accessing view of another project.
Related
I have created a new .Net Core project using Visual Studio 22. Inside of my project I have created a new area (it was created successfully and works as expected).
Upon creating a new scaffolded item, all of the assets (controller & views) are created, however the code generated in my views is not aware of area they were created in.
For example my structure is /Areas/Admin/Flags
I can hit /Admin/Flags/Index just fine.
However, all of the links and form actions point to /Flags/[Action]
It's as if the scaffolding engine was not aware that I was creating these assets inside of an area.
Any ideas?
Make sure app.UseEndpoints with area in the pattern is an early middleware extension in /program.cs. I added right below app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
});
It will automatically utilize the area in the route.
Also, don't forget to copy _ViewImports.cshtml into the root of the /areas/[area]/Views folder, else links won't be clickable.
I'm working on an ASP.NET Core 5 MVC project. My client wants a different link format, like:
http://studentfintech.app/short_form
But, at this time, the page link is:
http://studentfintech.app/Money/short_form
If I remove the MoneyController, this will be removed, but this is not accessible without a controller.
Please share your ideas to access this page according to this link:
http://studentfintech.app/short_form
This can be useful for you:
Routing in ASP.NET Core MVC
You can specify a route like this:
endpoints.MapControllerRoute(
name: "short_form",
pattern: "short_form",
defaults: new { controller = "Money", action = "short_form" });
I want to run a certain Asp.NET MVC 4 Controller when an URL -probably irrelevant with the controller name- is entered. For example, if the user opens the address "localhost:3364/abc/def", I want to run the controller with the name, for example, "SugarController". Is it possible, or do I have to start my URL with the word "Sugar"? I know that URL routing can be done by adding some code to Global.asax file in the project. But I don't exactly know how to manage this one.
Thanks in advance.
This should work
routes.MapRoute("Fixed", "abc/def", new { controller = "Sugar", action = "def"});
I have two controllers in my MVC4 Project.
One controller is in default controller name called Login.
another controller is in area .area name called HR.inside controller name called AddNewHire.
inside AddNewHire i written AddNewEmployee method.
in Login controller i am having one method .that name is LoginButton
inside LoginButton method i written
return RedirectToAction("AddNewEmployee","AddNewHire",new {area="HR"});
am getting Error Like
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /AddNewHireController/AddNewEmployee
Try using RedirectToRoute instead of RedirectToAction. What you would have to do is to define a route. Have a look at this MSDN link (Walkthrough: Creating an ASP.NET MVC Areas Application Using Multiple Projects
Im currently implementing MVC into a fairly large project and want to sort views into categories. MVC dont seem to understand this and Im having problems finding a clean solution. Basically I was hoping to solve this with routes, but it isnt working.
My folder structure in the project is like this:
- Controller
- SLResources
- FAQController.cs
...
- View
- SLResources
- FAQ
- (cshtml files in here)
Ive also tried adding a - FAQ folder after - SLResources in the controller folder structure.
Ive then made the following routing, with no luck:
RouteTable.Routes.MapRoute(
name: "FAQ",
url: "SLResources/FAQ/{action}/{id}",
defaults: new { controller = "FAQ", action = "Index", id = UrlParameter.Optional }
);
basically I would like to reach the FAQ by using this url: http://www.xxxxxxxx.com/SLResources/FAQ/
Is the only solutions to either create a dummy class that redirects to the proper views, or a custom ViewEngine?
Any tips?
If your goal is to have the url with SLResources/FAQ, then you don't need to create a separate folder in the Views.
Your route already does that for you. Leave your route as is, and put your cshtml files in the 'Views>FAQ' folder and it will work.