मुख्य सामग्रीमा जानुहोस्
~/writing

यो लेख अंग्रेजीमा छ।

.NET

ViewBag, ViewData and TempData in ASP.NET MVC

/ १ मिनेट पढाइ / Ejan Shrestha

ViewBag, ViewData, and TempData are all mechanisms provided by ASP.NET MVC to share data between controller actions and views.

ViewBag and ViewData are similar in that they both allow you to pass data from the controller to the view, but they differ in their underlying implementation.

ViewBag is a dynamic object that uses C# dynamic features to store and retrieve data. You can set values on the ViewBag object in the controller and then access those values in the view using dot notation. For example, in the controller, you might set a value like this:

ViewBag.Title = "My Page Title";

And then in the view, you could access that value like this:

code<title>@ViewBag.Title</title>

ViewData, on the other hand, uses a dictionary to store and retrieve data. You set values on the ViewData dictionary in the controller, and then you can access those values in the view using the ["key"] syntax. For example, in the controller, you might set a value like this:

 codeViewData["Title"] = "My Page Title";

And then in the view, you could access that value like this:

code<title>@ViewData["Title"]</title>

The TempData dictionary is similar to ViewData, but it is used to pass data between actions during a single user request. When you set a value in TempData in one action, you can retrieve that value in a subsequent action. However, once the request is complete, the TempData values are discarded.

In summary, ViewBag and ViewData are both used to pass data from a controller to a view, but ViewBag is a dynamic object, and ViewData is a dictionary. TempData is used to pass data between actions during a single user request

Resume.pdf

PDF डाउनलोड

Ejan Shresthaइजन श्रेष्ठ

Senior Software Engineer, backend and .NET modernisation

Senior software engineer in Kathmandu with 4+ years shipping .NET for insurance and enterprise. I own reliability and modernisation for an insurance platform of 50 .NET projects on Kubernetes: structured logging and tracing across old and new services, the plan off end-of-life .NET to .NET 10, and the fix for socket exhaustion across ~390 call sites.

Selected impact

  • ~390Ending socket exhaustion across the platform. The error class disappeared from production logs, and outbound HTTP now has one place for retries and tracing.
  • 1 IDOne trace from gateway to database. One correlation ID now follows a request end to end.
  • 61%From end-of-life .NET to .NET 10. A sequenced roadmap with known risks; the first services already run on .NET 10.
  • v16A public website on Next.js 16. Shipped to production with a tested rollback path.
  • 4A release standard people follow. Releases are predictable enough to schedule.

Experience

  1. Senior Software Engineer, Himalayan Everest Insurance

    Jan 2025 – present

    Kathmandu, hybrid

    • Own backend reliability and modernisation for an insurance platform of 50 .NET projects, deployed as 28 Kubernetes workloads, across accounting, claims, reinsurance and reporting.
    • Leading the upgrade from .NET Core 2.2, 3.1 and 5 to .NET 10, including the IdentityServer4 replacement.
    • Built structured logging and tracing across every service.
    • Upgraded the public website and CMS to Next.js 16, React 19, Strapi 5 and Node 24.
  2. .NET Developer, EKbana Solutions

    Jul 2022 – Nov 2024

    Lalitpur, on-site

    • Designed backend services for enterprise insurance workflows with ASP.NET Core, PostgreSQL, EF Core and Dapper.
    • Built REST APIs and integrations for customer portals, payments and external partners.
    • Ran background workflows on Hangfire with idempotency, retries and failure recovery.
    • Shipped on Docker, Linux, Nginx/Traefik and Kubernetes; worked on IdentityServer, JWT and RBAC.
  3. Dotnet Developer, NBIT

    Jan 2022 – Jun 2022

    Lalitpur

    • Built and maintained .NET Framework applications for client projects.
  4. Data Specialist, CloudFactory

    Nov 2017 – Jun 2022

    Kathmandu

    • Delivered high-accuracy data work for international clients while completing my degree.