NET Centric ComputingUnit 77 min read
Client-Side Dev in ASP.NET Core: Frameworks, Libraries & Modern Tools
Unit 7 of NET Centric Computing explores client-side development in ASP.NET Core, covering JavaScript frameworks (React, Angular, Vue), libraries (jQuery, Bootstrap), and integration techniques with ASP.NET Core APIs. It includes real-world examples like eSewa’s dynamic UI and Pathao’s real-time tracking, with hands-on
Client-Side Development: The Frontend Ecosystem
Client-side development is the backbone of modern web applications, transforming static HTML into dynamic, interactive user interfaces. In ASP.NET Core, client-side development involves using JavaScript frameworks/libraries to build responsive, single-page applications (SPAs) or enhance traditional server-rendered pages. This unit focuses on how these tools integrate with ASP.NET Core’s backend, enabling seamless data flow and real-time updates.
1. Why Client-Side Development Matters
Client-side code runs in the user’s browser, reducing server load and improving performance. Key reasons for its importance:
- Faster Interactivity: No full page reloads (e.g., eSewa’s payment form updates instantly).
- Offline Capabilities: Apps like Pathao’s ride tracker work with cached data.
- Cross-Platform Compatibility: Works on mobile, desktop, and tablets.
2. Core Client-Side Technologies
A. JavaScript Frameworks vs. Libraries
| Type | Examples | Use Case | ASP.NET Core Integration |
|---|---|---|---|
| Framework | React, Angular, Vue | Full-fledged SPAs (e.g., Daraz’s cart) | API calls via fetch() or Axios to ASP.NET Core |
| Library | jQuery, Bootstrap | UI enhancements (e.g., NTC’s form validation) | CDN inclusion or bundled with ASP.NET Core |
How they work:
- Frameworks (React/Angular) provide structure (components, state management).
- Libraries (jQuery) are modular tools for DOM manipulation or styling.
B. Single-Page Applications (SPAs)
SPAs load a single HTML page and dynamically update content via JavaScript. Example: eSewa’s dashboard fetches user data from ASP.NET Core APIs without refreshing.
Advantages:
- Smooth user experience (e.g., WhatsApp Web).
- Reduced server load (fewer HTTP requests).
Disadvantages:
- SEO challenges (solutions: prerendering with
ng universalfor Angular). - Initial load time (mitigated by code splitting).
Mermaid Diagram:
sequenceDiagram
User->>Browser: Loads SPA (React)
Browser->>ASP.NET Core: GET /api/user (API call)
ASP.NET Core-->>Browser: Returns JSON
Browser->>DOM: Renders UI dynamically3. Integrating Client-Side with ASP.NET Core
A. Fetching Data from ASP.NET Core APIs
Use fetch() or libraries like Axios to call ASP.NET Core controllers:
// Example: Fetching orders from Daraz’s backend
fetch('/api/orders')
.then(response => response.json())
.then(data => console.log(data));
ASP.NET Core Controller:
[HttpGet]
public IActionResult GetOrders() {
return Json(_orderService.GetAll());
}
B. Real-Time Updates with SignalR
For live updates (e.g., NEPSE stock prices), use SignalR:
sequenceDiagram
Client->>SignalR Hub: Connect()
ASP.NET Core->>Client: Push updates (e.g., stock price)
Client->>UI: Update DOMExample: A bank’s loan approval system updates in real-time without page reloads.
4. Popular Client-Side Tools in ASP.NET Core
A. React with ASP.NET Core
- Why? Facebook’s React dominates SPAs (e.g., Pathao’s driver app).
- Integration:
- Create React app separately, then proxy API calls to ASP.NET Core.
- Use
create-react-apporVitefor bundling.
B. Angular with ASP.NET Core
- Why? Google’s Angular is ideal for enterprise apps (e.g., Ncell’s billing portal).
- Integration:
- Use
HttpClientModuleto call ASP.NET Core APIs. - Example: Fetching user data:
this.http.get('/api/users').subscribe(data => this.users = data);
- Use
C. Vue.js with ASP.NET Core
- Why? Lightweight and easy to integrate (e.g., eSewa’s admin panel).
- Integration:
- Mount Vue instance in a Razor view:
<div id="app">@(await Html.Raw(ViewBag.VueScript))</div> <script src="~/vue-app.js"></script>
- Mount Vue instance in a Razor view:
5. State Management
A. Local Storage vs. Session State
| Method | Use Case | ASP.NET Core Role |
|---|---|---|
localStorage |
Save user preferences (e.g., Daraz theme) | No server involvement |
sessionStorage |
Temporary data (e.g., Pathao’s ride details) | Cleared on tab close |
| ASP.NET Core TempData | Short-lived data (e.g., form validation errors) | Server-side |
Example: A user’s cart in Daraz persists via localStorage until cleared.
6. Styling and Responsiveness
A. Bootstrap in ASP.NET Core
- Why? Pre-built components (e.g., NTC’s responsive forms).
- Integration:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" />
B. CSS Frameworks
| Framework | Best For | Example |
|---|---|---|
| Bootstrap | Rapid UI development | Ncell’s login page |
| Tailwind CSS | Custom designs | eSewa’s payment UI |
| Bulma | Lightweight alternatives | Small business websites |
7. Build Tools and Optimization
A. Bundling and Minification
- Why? Reduce file sizes (e.g., Pathao’s app loads fast).
- Tools:
- Webpack: Bundles React/Angular apps.
- Gulp: Minifies CSS/JS.
Example Workflow:
flowchart TD
A["Source Files"] --> B["Webpack"]
B --> C["Bundled JS/CSS"]
C --> D["ASP.NET Core Static Files"]B. ASP.NET Core’s wwwroot Folder
- Store static files (JS/CSS/images) here for automatic serving.
In the Real World
eSewa’s Payment UI
- Tool: React + ASP.NET Core APIs.
- How: Dynamically updates transaction status via
fetch()calls to ASP.NET Core’s/api/transactionsendpoint.
Pathao’s Ride Tracking
- Tool: SignalR for real-time driver location updates.
- How: ASP.NET Core pushes GPS data to clients without polling.
Ncell’s Billing Portal
- Tool: Angular + Bootstrap.
- How: Uses
HttpClientto fetch bills from ASP.NET Core’s/api/billsand renders them in a responsive grid.
Exam Tip
Focus on Integration:
- Questions often ask how React/Angular connects to ASP.NET Core APIs. Know
fetch(), Axios, and SignalR. - Example Question: "Explain how to call an ASP.NET Core Web API from a React component."
Answer: Use
fetch()or Axios to the API endpoint (e.g.,/api/orders), handle JSON responses, and update React state.
- Questions often ask how React/Angular connects to ASP.NET Core APIs. Know
SPA vs. Traditional MVC:
- Compare pros/cons (e.g., SEO, initial load time). Mention prerendering for Angular/React.
State Management:
- Differentiate
localStorage,sessionStorage, andTempData. Give a real-world example (e.g., shopping cart).
- Differentiate
Visuals in Exams:
- Draw a sequence diagram for API calls or a project structure for React + ASP.NET Core.
Code Snippets:
- Memorize:
- A
fetch()call to ASP.NET Core. - SignalR hub setup in ASP.NET Core.
- React component with API data.
- A
- Memorize:
Key Formula to Remember: For calculating bundle sizes (if asked):
Total Bundle Size = (JS Size) + (CSS Size) + (Image Size) - (Compression Savings)
Based on the TU BIT syllabus for NET Centric Computing (BIT351), unit 7.
Discussion
Loading…