I am interested into looking at SPA's with MVC. I realized I can use Kendo UI controls with this as well, which is great.
So I am following a post at http://a.shinynew.me/post/78038782111/a-kendo-ui-asp-net-mvc-spa-template which is interesting.
The issue is that I am experienced with mvc and razor, and it looks like this template takes the html route, which seems like a bit of a steeper learning curve, and won't be as easy to leverage my existing code. I can't figure out how to hook up new views to the MVC methods, everything hits the Home / Index method.
Then I read [link in comments because I need 10 rep to post 2 links] but the template that you download doesn't seem to have anything under Script/App or App. The project seems completely different now, irritatingly. But then, I noticed this:
You have two options for SPA views that will be loaded into the SPA:
standard HTML (.html) or ASP.NET MVC Razor (.cshtml) pages. Because
this article is intended for .NET developers—and a lot of enterprises
have server-side libraries and frameworks they’d like to continue
using in their views—I’ll go with the latter option of creating Razor
views.
So my question is, how could I convert the http://a.shinynew.me/post/78038782111/a-kendo-ui-asp-net-mvc-spa-template template to use Razor views instead of .html
Related
Can we scaffold an entity for making razor pages with paging & sorting & filtering features automatically without writing code for these features both back end and front end codes like third party's controls (grid) in asp.net webform or asp.net mvc?
Is there any package for that in razor page or in blazor?
at least how can we customize razor page scaffolding?
or which third party's grid control do you recommend for asp.net core and razor pages or blazor?
(I have vs code and .net core 3)
No, you can't right now do such scaffolding with Razor Components. The new framework is only in its early development stage.
The concept of razor page does not exist in Blazor (Razor Components). You may say Razor Component, which can act as a page if you add to it a #page directive, or a child component if you omit the #page directive, but "Razor Page(s) is a new aspect of ASP.NET Core MVC that makes coding page-focused scenarios easier and more productive"
Language can be the source of misunderstanding, and I had to read your post twice in order to under it.
I believe that Telerik is right now frantically creating grid control to work in Blazor. See here: https://www.telerik.com/blogs/introducing-the-telerik-ui-for-blazor-early-preview
As far as I remember, there are some samples made by the community... look for it in the Blazor web site. But why won't you develop it yourself. This is the best way to learn Razor Components.
Hope this helps...
I'm liking the Razor syntax that Microsoft has developed for inline coding in their WebMatrix product (http://en.wikipedia.org/wiki/Microsoft_WebMatrix).
Now that Visual Studio SP1 has RTM'd, is it possible (and/or planned) to enable the use of Razor syntax in ASP.NET Webforms?
We (the ASP.NET team) currently have no plans to support the WebForms page model using Razor syntax. Furthermore it is unlikely that we would ever seriously consider this as the models are too different to make the two work together.
You can use Razor pages without MVC; this is called ASP.Net WebPages.
Just add .CSHTML files to a normal ASP.Net 4.0 project.
I explained how this works in my blog.
You could possibly integrate it using the RazorEngine available from Codeplex. It allows you to process razor outside of MVC. Though you don't get all the features you get from the MVC version of Razor, such as #Html and #Url and others.
I dare say that Microsoft have considered it, but there is no official word on the subject. Since you are not supposed to have C# or VB code in the ASPX file, you have to wonder about the point of adding Razor support to Web Forms. The code behind would still be a (partial) class file. You wouldn't put Razor there any more than you would put it in a class file in Web Pages or MVC. And swapping Server Controls and all that good declarative stuff for Html Helpers removes one of the key reasons for going the Web Forms route, IMO.
This really isn't that difficult to do. Working on it right now. Grab RazorEngine from CodePlex. It lets you compile Razor cshtml/vbhtml files into a class at runtime.
You can then take that class, and use it from a ASP.Net server control, inside its Render method. This is a great way to get HTML out of the body of a server control. Much, much cleaner.
Now, you can also add some methods that you can invoke from Razor. For instance, add something like RenderChild. Additionally, you could set the Server Control itself as the Model available to Razor. You could then invoke into the server control. Including doing something like grabbing one of it's child controls and invoking Render.
First and foremost reason to update big old MVC2 project for me is the Razor engine. Now following this instructions
I successfully converted the project without yet touching .aspx and .ascx files.
1) Can you guys tell me now, how can I convert Master pages to layouts, and start converting pages and user controls without breaking any existing MVC2 pages? (it's a large project, can't do them all at once). Can I somehow use old master pages as layouts in razor pages?
I converted a couple of partial aspx pages which don't use a master page.
I used Telerik's aspx2razor converter - it helps although you still have to do a lot of manual revisions.
2) Is there any other better tool out there?
You can use Razor and the normal views side by side. By default, MVC3 looks for razor first, then will fall back to the WebFormsViewEngine.
So you should have no problem, and you can tackle each page in time as you see fit.
I am working on moving an application from MVC2 ASPX to MVC3 Razor, and is quite stuck moving a baseclass for more MasterPages in old MVC2 application.
The baseclass is used for automate include of css and js on pages in order to ease quickfix and debugging when developing application in local environment, but when running application in production environment it has to update and include single minimized css and js files delivered from a external CDN.
The code needs to know about the View file eg. "~/views/home/index.chtml" and/or the Layout file eg. "~/Views/DefaultNoLogon.Master" in order to include and handle css and js files correct.
I tried to implement own baseclass using the pageBaseType in Razor part of web.config, but it seems like it is executed both for View and Layout file, and I could not find a execution point where information about both View and Layout file is present. I also tried to implement the file logic using a HtmlHelper, but I can only access information about the View file and miss information for Layout file for View.
I don't want this kind of code to be implemented in Route, Controller or ViewModel since it should be related directly to generation of Views.
Any ideas how to get information about View and Layout files in MVC3 Razor app?
Well, never mind my question.
I redesigned my logic for automatic rendering of js and css files, which actually is more simple and works better. My Mvc3 Razor app is now capable to take all js and css files for a view (including css and js for all layoutpages) and render them into single minified files.
Works like a charm, and I guess it's more future proof than my old solution, unless Guthrie make fundamental changes in layoutpages and Html helpers in Mvc4 or later.
I realize this is probably a fundamental thing I should know but I am self-teaching myself C# and asp.net so I am a little lost at this point.
I right now have 2 pages. One is an .aspx (with aspx.cs file included) that is blank and html is generated for it from a Page_Load function in the cs file. The HTML is very simple and it is just an image and some text.
The second file is a shtml file which has lots of things, serverside includes, editable and noneditable areas. I want to put my webapp into this file. My asp.net app uses Response.Write to just write out the html. This does not flow well with this page as all that does is write it at the top of the page which is because it is ran first and generates it at the top.
How can I make it to where I can generate HTML code inside the page, like within a specific DIV so it does not mess up the page. Where would a starting point be in learning how to do that.
I should note that I do not need any interaction from the user. All of this should generate right away.
I think you need to read up on some basic ASP.Net documentation and tutorials. Response.Write is not the correct approach - you need to understand how the ASP.Net page lifecycle works and how WebControls are used to render the html.
ASP.Net tries to abstract away having to create your html manually for the most part.
So if i have understood the questions correctly.
You already have an existing page/application (the shtml file) that you want to extend with some new ASP.NET components by including output from the ASP.NET page in the existing page?
This is as not something that is out of the box "supported" by ASP.NET and you "won't" be able to execute the aspx page using SSI. But you can do the opposite, an ASP.NET page does support SSI. So if you are not using any other scripts in the shtml file this might be a solution.
Otherwise the only common solutions would be either to use an AJAX framework and let it call the ASP.NET from within the existing pages or to use an iframe solution. In both cases the client will be resposible for making the calls to the ASP.NET pages and merging the results.
And then you have a issue with controlling the output from the ASP.NET page?
The Polymorphic Podcast has a good article on Controlling HTML in ASP.NET WebForms .
You can add a Literal control to the page inside the div:
<div>
<asp:Literal ID="litMarkup" runat=server />
</div>
then in your code-behind:
litMarkup.Text = "<strong>Your markup</strong>";
I don't know how well this would work for you, but could you try using an iframe to house the ASP.NET page? This should keep it in the specified region and not overwriting your shtml file. It may be something to think about.
If it is necessary that you generate your HTML output from C# code, and you would use this in more than one place, I think you may be thinking of something like what are called ASP.NET Custom Controls (not to be confused with "User Controls"-- though you probably could put together a solution with those as well, using a Literal control as another person suggested). The MSDN documentation would be a good starting point. In general, though, the writing-out-HTML-yourself-from-code model (like you would with, say, CGI applications), is not the usual ASP.NET model of development, as it largely defeats the point of using ASP.NET at all. You'd mostly want to do this sort of thing if you are writing your own web control, though this might be exactly what you are doing (hard to tell from the description).