20

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.

2

3 Answers 3

34

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

7
  • Great answer man, I just want to clarify something, If I still use web forms in .net Framework 4.5 for a new project in 2018, will this be considered far from what we have got from Microsoft regarding web development ?
    – user123456
    Aug 2, 2018 at 2:46
  • 2
    The use of "Classic ASP.NET Web Forms" (ie. aspx, ascx, master pages & friends) is a departure from the future of .NET and perhaps should be viewed as existing only for backward-compatibility. There have been numerous advances along the ASP.NET web stack over the past 15+ years from profile management to hosting runtimes -- and with .NET Core there is no real migration path/plan for older versions of the ASP.NET web stack. "New developers" should view these as separate tracks of experience, "new developers" will probably want to avoid the classic ASP.NET templates/projects entirely early on. Aug 2, 2018 at 5:03
  • @ShaunWilson - Microsoft has not released a SSRS Report Viewer for ASP.NET Core or MVC 5; which leaves us with Web Forms. Is it possible to host/execute Web Forms within an ASP.NET core project? Similar in that MVC 5 could host Web Forms? For example, if I ran ASP.NET core using .NET Framework 4.7.2 - could I also host a Web Form within that site?
    – VAUser1
    Sep 19, 2018 at 20:24
  • @VAUser1 The answer to this sort of question should always be "yes, it's possible" because it's an engineering problem; though it would be "unusual", and as these are two separate stacks "a site in IIS could leverage both frameworks" but the stacks would not be truly intermingled. Separately, there is Alan Juden's Report Viewer for .NET Core, however, I have no personal experience with this component.. the community responses suggest it would be worth looking into. Sep 19, 2018 at 21:46
  • 1
    @user123456 speaking as someone who helps maintain a large legacy ASP.NET Web Forms application, with the dead-ending of Web Forms in Core 5, I would steer clear of it for new projects (and I say this with some nostalgic fondness for Web Forms). Jan 15, 2020 at 17:20
16

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).

6

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.

8
  • 1
    Visual Studio 2019 for Mac provides a template named 'ASP.NET Web Forms Project' which seems to provide most of the classic ASP.NET components. Jun 7, 2019 at 19:06
  • @PhilipJespersen I see ASP.NET Web Forms in Visual Studio 2019 on Windows as well but only for .NET Framework 4.7.2 and lower. I don't believe it will be present for Core. I only see ASP.NET Core Web Application, no Web Forms template present on my PC. Jan 15, 2020 at 17:24
  • 1
    @JeffMergler: There are no plans to port WebForms. The official alternative (for new projects) is to use ASP.NET Core Razor Pages
    – Tseng
    Jan 15, 2020 at 23:06
  • The Webforms template works in Visual Studio 2019 for Mac, so it must be using .NET Core in Mac. Feb 19, 2020 at 2:38
  • @FernandoGonzalezSanchez .NET Core is fully compatible with .NET Framework, so this is not surprising.
    – TylerH
    Jun 2, 2021 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.