A gentler way to get on board C# (and have access to all the .NET libraries and frameworks) without learning the more complicated MVC pattern (which can be overkill for simpler projects) is using C# Razor Pages syntax.
I mean, you can even assign your C# variable values to your VueJS or JS code like this. It’s not a neither or. You can use both C#, JS, or other front-end frameworks at same time.
@section customscript {
<script src="~/build/scripts/app-min.js"></script>
<script>
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
// NOTE: Vuejs should come before CKEDITOR script, otherwise the editor does not work.
// v-model will ignore initial value, checked or selected attributes of form elements.
// app.data will be the source of truth
var app = new Vue({
el: '#add-article-form',
data: {
publishDate: '@PublishDate',
originalUrl: '@OriginalURL',
originalUrlImported: 'N',
issueEdition: '@IssueEdition',
volumeNumber: '@VolumeNumber',
issueNumber: '@IssueNumber',
title: "@Title",
subtitle: "@SubTitle",
sortOrder: '@SortOrder',
author: "@Author",
articleSummary: '@ArticleSummary',
articleText: '@ArticleText',
articleFooter: '@ArticleFooter',
tags: '@Tags'
}, // end of data
// rest of stuff here....
You can call custom C# functions in libraries and extensions you made, from the HTML page.
<div id="easytaghelp" class="col-sm-4" >
@Utilities.DisplayEasyTags( )
</div>
On your HTML/Razor page template, you can use whatever .NET library you need. Embed it on the page.
@using System.Text.RegularExpressions;
@using System.Security.Cryptography;
then later on, use it on your page.
// short summary/description for this article
if (String.IsNullOrEmpty(Article.ArticleSummary))
{
// use full story text for our summary
articleSummary = ASP.Utilities.RemoveHTMLTags(articleText);
articleSummary = articleSummary.Substring(0,400); // get first 400 char
articleSummary = Regex.Replace(articleSummary, @"\r\n?|\n", " "); // remove line breaks
} else {
articleSummary = Article.ArticleSummary;
}
Connect easily to an SQL Server database, make SQL queries!
var db = Database.Open("MYDATA");
string query = "Select * FROM Articles WHERE ArticleID = @0 ";
var Article = db.QuerySingle(query, articleID);
db.Close( );