Simple ASP. net core single-page Web application "Framework", asp. netcore

Source: Internet
Author: User

Simple ASP. net core single-page Web application "Framework", asp. netcore

I don't know much about ASP. net core. I don't know if it's a duplicate or nothing. This Demo is like this:

1. Very simple or primitive;
2. added a Page concept (equivalent to the MVC View) to a single-Page Web application)

3. Ajax redirects to the new Page without refreshing, and supports refreshing the Page in the H5 browser, and moving forward and backward to other pages.
4. MVC-like development mode. Action provides Data, Js rendering View, Data and View development separation.

 

Full code can access https://github.com/fonshen/Fonshen.SPA

 

They are all very simple things, as if there is nothing to say, simply look at the core application code:

1. The basic page/View/Shared/Default. cshtml on a single page shows a menu. Click the menu to switch to a new topic without refreshing the menu. You can refresh the new topic and move it back.

<! DOCTYPE html> 

2. Controller class. Each return this. Page (data) Action corresponds to a Page

using Fonshen.SPA.Extensions;using Microsoft.AspNetCore.Mvc;// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860namespace Fonshen.SPA.Controllers{    public class HomeController : Controller    {        // GET: /<controller>/        public IActionResult Index()        {            var data = new            {                content = "index"            };            return this.Page(data);        }        public IActionResult About(int id)        {            var data = new            {                content = "about",                page = id            };            return this.Page(data);        }        public IActionResult Contact()        {            var data = new            {                content = "contact"            };            return this.Page(data);        }    }}

3. Three actions correspond to three Js rendering files

/// Js/Home/Index. the js file is responsible for rendering Index Action // Page. data corresponds to the dataPage of the server. render = function () {Page.Body.html ("Index:" + Page. data. content) ;}; // js/Home/About. js files are responsible for rendering About ActionPage. render = function () {Page.Body.html ("About-> NO." + Page. data. page + "page") ;}; // js/Home/Contact. the js file is responsible for rendering the Contact ActionPage. render = function () {Page.Body.html ("Contact:" + Page. data. content );};

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.