The code I wrote: (file Index.cshtml)
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
#using WebApiSimple.ViewModels
#model ValuesViewModel
but the word model is not recognized. I started from a WebApi template and now I want to convert to a MVC. The webapi works but as I mentioned I cannot write razor views because the intellisense does not recognize the word "model"
The project was missing the web.config file in the View folder. I added that from another mvc project and now it works.
Related
We have a content page that runs a boolean check in our controller and we are moving that page to DNN. Is there a way to keep running that check using the Razor Host module?
I would basically show or hide button based on the status of a registration process.
My manager found the solution:
It turns out if you create a static file and save it in the Components folder (remember this is for DNN modules), you can just make a call to that class and its methods from within the Razor Host module as such:
#using MYNAMESPACE.Modules.Myproject.MyModule.Components
Some html
#{ var isRegistrationOpen = MyStaticClass.IsRegistrationOpen(); }
Registration Status: #isRegistrationOpen
I have created web application - Asp.Net MVC in .NET Core.
This application contains some Razor Views but I would like to share these views to another application like for example with DLL or like middleware.
Here is some information about example with distribution Controllers but around Views nothing special - https://learn.microsoft.com/en-us/aspnet/core/mvc/advanced/app-parts
I've tried add Controller like this:
var assembly = typeof(Project.HomeController).GetTypeInfo().Assembly;
services.AddMvc()
.AddApplicationPart(assembly);
This works very well, but I don't know how add the Views.
How can I distribute the Razor Views to another application? Is it way import them like a middleware to the MVC middleware?
You can create a normal netstandard1.6 library-i.e., where your controllers are, and embed the view resources into that dll in your csproj using the following:
<ItemGroup>
<EmbeddedResource Include="Views\**\*.cshtml" />
</ItemGroup>
After that, you can then register these using the RazorViewEngineOptions:
// Add views provided in this assembly.
services.Configure<RazorViewEngineOptions>(options =>
{
options.FileProviders.Add(
new EmbeddedFileProvider(typeof(ClassInLibrary).GetTypeInfo().Assembly));
});
Where "ClassInLibrary" is a class in your library that you can then get the assembly information from.
I would like to build emails in dotnet core 1.0 using the Razor engine, but I cannot work out how to do that.
I have created a view model containing the data for the view and I have made a view and run that view in code:
var confirm = new ConfirmEmailHtmlViewModel();
confirm.CallbackUrl = callbackUrl;
var message = View("ConfirmEmailHtml", confirm);
What I cannot figure out is how to extract a string containing the rendered view from 'message'.
Is this possible and if it is how do I do that?
I have answered this here: Where are the ControllerContext and ViewEngines properties in MVC 6 Controller?
The original answer on that question was for a pre-release of ASP.NET Core and not the 1.0 release.
I am fairly new in MVC4. I'm working with C# Razor view engine using Entity Framework.
I wanted to add new view model that incorporated multiple models (obviously). But I needed a new view. So I created new folder inside Views named "MasterView" with a sample Index.cshtml inside, linked it inside _Layout.cshtml with
<li>#Html.ActionLink("Klick me", "Index", "MasterView")</li>
and when I ran my application, all the default links worked except that one (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. ). Am I missing some permission for that page inside some project file? How do I fix it? Thanks in advance.
In MVC you link to Actions inside Controllers rather than pages/views.
In this case you would need a MasterViewController (in the Controllers folder) with an Index action like this:
public ActionResult Index()
{
return View();
}
This will render and return your Index.cshtml file.
I have a project developed in MVC2 / ASPX / c#. I updated it to MVC and it works well. Just noticed when I publish it, get propblem with System.Web.Helpers; and copy it manually.
Since the application is very complex I develop additional compenents in new projects. I used MVC3 ASPX views, in my view I use:
var series = <%= Html.Raw(Json.Encode(ViewBag.Series)) %>;
it works great, when I integrate the controller, view and master page in the older application I get this error:
The name 'Json' does not exist in the current context
Would appreciate your suggestions.
The problem was in System.Web.Helpers, I was using version 2.0; it should be version 1.0.