<form asp-action in areas. Can`t find a controller. Asp.Net Core
Clash Royale CLAN TAG#URR8PPP
<form asp-action in areas. Can`t find a controller. Asp.Net Core
I have one form in a page in the main area. Views/Home. Code and I want that you see the screenshot.
VS make a color for this form. And it is working with controller
<form asp-action="LoadImg" asp-controller="Account" method="post" enctype="multipart/form-data">
<input type="file" name="ImgPost" /><br>
<input type="submit" value="Загрузить" />
Next, I want to make the same but in Areas/Admin/Views/Home/Private
and I see next
Areas/Admin/Views/Home/Private
First of all, I want to know why the color in VS is different? And why when I click submit it isn't going to my controller in Areas/Admin/Controllers/Home/Load - action
Areas/Admin/Controllers/Home/Load - action
as usual, I use in areas Razor and its working. It is example of the same page in areas @using (Html.BeginForm("PostSave", "Home", FormMethod.Post))
@using (Html.BeginForm("PostSave", "Home", FormMethod.Post))
<form asp-action="Load" asp-controller="Home" method="post" enctype="multipart/form-data">
Thanks
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Thanks. Color in VS is working now. Need the second problem.
– FX_Sektor
Aug 6 at 14:32
And the second problem is done with your advice. Answre for question and I will do it as right! Thanks man!
– FX_Sektor
Aug 6 at 14:40
Each area needs its own
_ViewImports.cshtml
(with the same tag helper import as in the main one). As far as route resolution goes, you need to specify the area, most likely, even if the area is "no area" (i.e asp-area=""
).– Chris Pratt
Aug 6 at 19:48
_ViewImports.cshtml
asp-area=""
1 Answer
1
It sounds like VS intellisense isn't loading your tag helpers for your MVC area. You can register the tag helpers explicitly in your view by adding the following line at the top:
using @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
using @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Alternatively add a _ViewImports.cshtml
containing this line to your area, or copy the one from your main ~/Views
folder.
_ViewImports.cshtml
~/Views
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Try the first answer to the similar question here - stackoverflow.com/questions/43269184/… - it sounds like VS intellisense isn't loading your tag helpers for your MVC area so you can do this explicitly using
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
at the top of your view.– getsetcode
Aug 6 at 14:15