ASP.NET csharp view without razor and aspx - c#

I'm developing a SPA with ASP.NET MVC for back-end and i was quite curious - Is there any way to build view only using c# to generate my html without using any razor pages or aspx?

You can do this by returning a content, more info here

Related

Is possible includes REACT in MVC.net project?

The project is MVC .NET and the view have RAZOR and Javascript + Jquery.
I really would use react for create new components , I really say if i could combinate react, razor and javascript in the views cshtml.

ASP.NET Core 2.1. Razor UI Class Library in MVC View

I'm currently working on an ASP.NET Core 2.1. RC1 Final (May 2018) demo application. I try to use the new Razor UI Library in my ASP.NET Core MVC application.
Thus, in my Solution I have 2 Projects:
ASP.NET Core MVC application
Razor Class Library
The structure of my Razor Class Library is very simple:
RazorClassLib1
Areas
MyFeature
Pages: Page1.cshtml
The cshtml of Page1.chtml looks like that:
#page
#model RazorClassLib1.MyFeature.Pages.Page1Model
#{
Layout = "_Layout";
}
<h1>Hello From the Razor ClassLib1</h1>
Now I want to use this Page1.cshtml Razor component in my MVC View. This feature would be useful to organize and reuse razor pages within my application.
Unfortunately I have no idea how to achieve this. I was following this example:
http://www.talkingdotnet.com/asp-net-core-2-1-razor-ui-as-class-library/
though it seems to work only for a razor page project, but I would need it in my MVC projct.
Do you know how to use a Razor Class Library in ASP.NET MVC Core 2.1. Views?
Thank you very much.
https://gunnarpeipman.com/aspnet/razor-class-library-mvc/
explains how to set it up.
There are some things to know:
Controllers must have AreaAttribute
Web application must have area route defined.
I think there work arounds using the areas, but I am researching this myself. will update the answer when I have figured it out.
Below link also explains how to make the area name dynamic:
https://blog.tech-fellow.net/2018/11/11/razor-ui-class-library-with-dynamic-area-name/

Is Razor compulsory in ASP.NET MVC 5? [duplicate]

This question already has answers here:
Using ASPX View Engine with MVC 5
(2 answers)
Closed 7 years ago.
I am new to ASP.Net MVC 5 and I want to know if Razor view engine is compulsory, or can you use ASPX view engine?
I try to create new application but I am not getting option to change the view engine.
Razor views are not compulsory. You can use aspx views. When creating your project there is a dropdown that allows you to select which view engine you want the template to use, if you are creating a project from a template.
However, this option doesn't make any difference to your project apart from the views that vs creates in the template. For example, change the name of one of your views, eg. Change home.cshtml to bob.cshtml. Run the project and navigate to the page that uses this view. You will get an error page which displays a list of views that the framework has attempted to find in different folders. This is an operation that uses convention and is the default method mvc will use to find views. Anyway, in the list you will see aspx and cshtml files, so you can go ahead and create an aspx view and mvc will pick it up. Note that the order of the list in the error message is the order mvc will look up each view. It will use the first one it comes across.
Razor views are not compulsory in ASP.net MVC..in ASP.net MVC there are two view Engine are there:
Razor View Engine:
1.Razor View Engine is an advanced view engine and introduced with MVC3. This is not a language but it is a markup syntax.
2.In Razor View Engine we use Layouts.
3.Razor Engine is a little slow compared to Aspx Engine.
Web Form/Aspx View Engine
1.ASPX View Engine is the default view engine for the ASP.NET MVC that is included with ASP.NET MVC from the beginning.
2.In ASPX View Engine we use masterPages.

MVC5 razor templates client server

Is it possible to use Razor for client and server side templates for MVC5? I now have to refactor a lot of my project to using AJAX, and client side template rendering. I was hoping to find something so that I won't have two separate template files for the same view. All my views are now made in Razor.
The project is using MVC5 and the latest Razor (version3)
Thanks in advance!
I doing the same investigation. Razor template rendering in javascript would be the ideal soluion...
Maybe this could be the good enter point
http://www.fidelitydesign.net/?p=375
https://github.com/kirbysayshi/vash
I also looking for template engine which could work for both MVC5 server and client side. I found jade template engine and Spark framework for asp. Spark can undestnd Jade sintax and javascript has Jade template engine. It seams like I found the solution but Spark framework stop developing on mvc3 stage... the same thing for nustache. It is annoying stopper.

percentage tags in cshtml

Following along on a tutorial in MVC, would you tell me the alternative to this in a ASPX page
<div>
<%=ViewData["CurrentTime"]%>
</div>
In a cshtml page, the default view type in MVC 4 on VS2013. When I try the above, the literal meaning is displayed. i.e. ViewData["CurrentTime"] instead of the value DateTime.now
When you using a cshtml. You are working with Razor engine.
In Razor engine, You need to use # like
#ViewData["CurrentTime"]
<%=ViewData["CurrentTime"]%> is a ASP.Net engine code
There are two engines in MVC: Razor and ASP.NET WebForms.
.cshtml filles are the files using Razor engine and this is a default engine of ASP.NET MVC from the third version.
The syntax you are using would work with the old WebForms engine.
So you should write:
#ViewData["CurrentTime"]
in case you use ViewData or
#ViewBag.CurrentTime
in case you use ViewBag which is more common when using Razor view engine and in general newer version of ASP.NET MVC .

Categories