Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of WebForms in ASP.NET Core?

I am doing my final year project in Computer Science and the project is a system for managing a college, like openSIS, but using ASP.NET Core to build it.

I need help on how to Add, Update, and Remove data using regular HTML forms, such as via <form/> and <input type="submit"/>. I knew how to do this in WebForms, but not in ASP.NET Core.

like image 826
Mr. A Avatar asked Mar 04 '17 17:03

Mr. A


People also ask

Is Web Forms in .NET Core?

ASP.NET Web Forms isn't supported in ASP.NET Core (nor are ASP.NET Web Pages). Typically, the functionality of these pages must be rewritten when porting to ASP.NET Core. There are, however, some strategies you can apply before or during such migration to help reduce the overall effort required.

What replaced ASP.NET Web Forms?

Blazor has a lot in common with ASP.NET Web Forms. Both frameworks offer component-based, event-driven, stateful UI programming models. The main architectural difference is that ASP.NET Web Forms runs only on the server. Blazor can run on the client in the browser.

What is ASP.NET Web Forms in C#?

ASP.NET Web Forms is a web application framework and one of several programming models supported by the Microsoft ASP.NET technology. Web Forms applications can be written in any programming language which supports the Common Language Runtime, such as C# or Visual Basic.


3 Answers

What you're asking to do is possible "out of the box" with ASP.NET Core and does not require a third-party solution.

Solution #1: ASP.NET Core Razor Pages

Microsoft - Introduction to Razor Pages

This is probably the most direct approach with the least to learn, and it is the modern equivalent to "Classic ASP.NET Web Forms." You are probably asking about this:

The basic idea is you create an "ASP.NET Core Web Application" project in Visual Studio and select the "Web Application" project template (confirming that ".NET Core" is selected in the template selection dialog before you click OK.)

You can then add "Razor Pages" containing HTML, CSS, and JavaScript, and use a simple post-back method via a regular HTML Form with a Submit Button. The link above has a topic on doing just that.

Solution #2: ASP.NET Core MVC

Microsoft - Overview of ASP.NET Core MVC

This is the second-most direct approach but does require you to grasp MVC concepts: Models, Views and Controllers. Implementing Razor Pages would only require you to grasp HTML and Razor Page code-behind, however, MVC as a pattern will provide your resulting project with a more maintainable and testable approach to the project.

The basic idea is to scaffold an "ASP.NET Core Web Application" project in Visual Studio, then select the "Web Application (Model-View-Controller)" project template.

Instead of adding Pages you add Views, to do anything useful these Views will have corresponding Controllers. There will also be Models defined, as you would see in a Razor Pages solution. In the case of MVC the Models are posted to your Controllers via Actions.

The link above covers the subject in detail, and there are numerous Stack Overflow posts on general MVC concepts.

Solution #3: RESTful Web APIs and Client-Side JavaScript

Microsoft - Building Web APIs

This is probably the least direct and most-technical approach. You will want to be familiar with "JavaScript" and "XHRs", "JSON" (or XML, but JSON has become de facto), and you will want to be versed in what it means to be a "RESTful Web Service" ie. that HTTP supports basic verbs to POST, GET, and DELETE a resource.

The basic idea is you create an "ASP.NET Core Web Application" project in Visual Studio using the MVC scaffold. You then implement Controllers to behave as RESTful web services. You can add Razor Pages and/or MVC Views to deliver the HTML and JavaScript.

With this approach you can create "Single-Page Applications" that never need to reload, where the HTML and JavaScript for the entire application can be delivered up-front and then RESTful web services used to modify the UI at the client. This can get advanced, and most developers will want to look into using a client-side templating engine. The leanest and simplest to use is probably going to be KnockoutJS, but others are more popular (and more complex.) Knockout has the value of solving a very specific problem: data-binding an HTML UI to JavaScript objects.

Regardless of the approach you take, start here: Microsoft - Get Started with ASP.NET Core

like image 136
Shaun Wilson Avatar answered Sep 21 '22 21:09

Shaun Wilson


If you like the Web Forms way of development, or if you have a large ASP.NET Web Forms application and you need to implement new pages in it, you can try DotVVM.

It is not "Web Forms on .NET Core", but:

  • many concepts in DotVVM are similar to ASP.NET Web Forms (postbacks, server controls, master pages, even the names of the controls and page lifecycle events)
  • it is easy to learn for ASP.NET Web Forms developers
  • no cryptic viewstate hidden field
  • the controls don't produce ugly HTML
  • the MVVM pattern is used
  • no need to know or write JavaScript - C#, HTML and CSS is enough to start coding
  • DotVVM supports both .NET Core and full .NET Framework
  • can be added to existing ASP.NET Web Forms or MVC applications on .NET Framework
  • DotVVM is open source
  • Visual Studio extension with IntelliSense and project templates

Disclaimer: I am one of the authors of DotVVM. This post is not meant to advertise the project, I just believe it responds to the question because the main motivation to build DotVVM was the fact that Web Forms are not ported to ASP.NET Core, and many people is looking for the similar way of building web applications. DotVVM is not a port of Web Forms to .NET Core. Our intent is to build a framework which is conceptually similar, but which avoids the things Web Forms were criticized for (viewstate, testability and ugly HTML output).

  • DotVVM GitHub
  • Documentation
  • Gitter Chat
like image 44
Tomáš Herceg Avatar answered Sep 17 '22 21:09

Tomáš Herceg


If you are referring to WebForms from ASP.NET (before MVC webstack came), there is no WebForms for ASP.NET Core and unlikely to ever be ported.

There is however a similar project (usually referred as Razor Pages or View Pages, see RazorPages GitHub repository) which allows to create Razor views which are not backed by a controller.

But as far as I know it's not release ready (there is no nuget package for it on nuget.org) and you'd have to use some previous from nightly builds or stable myget repositories.

like image 33
Tseng Avatar answered Sep 21 '22 21:09

Tseng