Posts

Best Way to manage session in .NET core centrally.

Create this common class and create 2 method for one session One method is for set value and second method is used for get value from session. This is also known as extension method concept in C# .NET. After creating this class you can simply set and get value from session. example : HttpContext.Session.InstitutionId(Id);  -> Here I we are set value in session. Id =Convert.ToInt32(HttpContext.Session.PortalUserId()) -> here we are getting value from session. using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Text.Json; using System.Web; namespace Z.App.Helper {     public static class CentralSession      {         private static string PORTAL_USER_ID = "PortalUserId";         private static string INSTITUTION_ID = "InstitutionId";         private static string ISADMIM = "IsAdmin";          ...

Best way to submit from using Ajax post method in ASP.NET MVC

  jQuery Code :   function Login() {         debugger;         var hasError = Validate("#divUserLoginContainer");         if (!hasError) {             var url = '/UserLogin/SignIn';         }         $.post(url, $('#frmUserLogin').serialize(), function (data) {             if (data.isSuccess == true) {                 debugger;                 swal({                     title: "Success",                     text: data.message,                     icon: "success",                 })                     .the...

Get error message from ModelState in c# mvc

public async Task<JsonResult> SignIn(UserLoginViewModel model)      {        if (!ModelState.IsValid)       {               _returnModel.Message  = ModelState.FirstOrDefault(x=>x.Value.Errors.Any()).Value.Errors.FirstOrDefault().ErrorMessage;        return Json(_returnModel);         }      return Json(_returnModel);   }

Cast any C# object to specific type of object.

ReturnModel returnModel = new ReturnModel();  returnModel = await fileDownloadService.GetUploadedFiles(URL);   List FilesList = new List ();   var Filelist = returnModel.Data as List ;  // Here I want to convert returnModel.Data into the List

Display Image preview on Edit time

Controller Code  public async Task<IActionResult> EditBlog(string Id)         {             DropDownInitialize();             _returnModel = await _blogDetailsServices.GetBlog(Id);             if (_returnModel.IsSuccess)             {                 string path = ((EduWeb.Data.Entity.tblblogdetails)_returnModel.Data).ImagePath; // this Line Represent path coming from database                   int pos = path.LastIndexOf("\\") + 1;                 ViewBag.image = path.Substring(pos, path.Length - pos); // Adding  in View Bag                 return View(_returnModel.Data);             }             else ...

How to rollback and commit transection in Asp.net MVC

 Example Of Rollback And Commit Transection In Asp.Net MVC ...  using (var _Context = new IRISDevMultiTenantEntities1())             {                 using (DbContextTransaction dbTransection = _Context.Database.BeginTransaction()) // Create a object of DbContextTransaction                 {                     try                     {                         tblCompany obj = new tblCompany();                         obj.Company_Name = CompanyName;                         obj.Logo_Filename = null;                         obj.Date_Cre...

jQuery toasted message example

Image
 Package  :  For Toasted message you need to download toast package from nugate  package manager .   <package id="toastr" version="2.1.1" targetFramework="net472" /> Import three script in page :  <link href="~/Content/toastr.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="~/Scripts/toastr.js"></script> Example :   $.ajax({             type: "POST",             url: '@Url.Action("SubmitData", "Emplyee")',             data: FormData.serialize(),             success: function (data) {                 debugger                 if (data.success == true) {                     toastr.success('Su...