Posts

How to Show only certain characters and bind '...' at end in mvc view in c#

  <span class="text-muted"> //here we show upto 200 characters and then '...' are shown @(item.Content.Length > 200 ? item.Content.Substring(0, 200) + "..." : item.Content) </span> 

How to Remove html tags from string in c#

  private List<ArticlesEntity> RemoveHtmltags(List<ArticlesEntity> articles)         {             List<ArticlesEntity> artls = new List<ArticlesEntity>();             artls = articles;             foreach(var item in artls)             {                 if (item.Content != "" && item.Content != null && item.Content != string.Empty)                 {                     item.Content= Regex.Replace(item.Content, "<.*?>", " ");//here html tags are removed                 }             }             return artls;         }

How to Preview the image and download which is in base64string format in mvc view using C#

  <div class="col-lg-9 col-xl-6">                                                     @if (reclaimdetai != null)                                                     {                                                         @foreach (var item in reclaimdetai.RequestFileList)                                                         {                                 ...

How to Change Layout based on viewbag value in mvc view using Mvc,C#

 @{     if (@ViewBag.lang == "en")     {         Layout = "Layout Name 1"; //This content uses above layout     }     if (@ViewBag.lang == "ar")     {         Layout = "Layout Name 2"; //This content uses above layout     } }

How to Get the current url and redirect to other url(case:button click english to arabic screen using parameter in url) using jquery,mvc,c#

   <a class="btn btn-icon btn-clean btn-lg w-40px h-40px btnlang" id="btnlang" > Change Lang </a> sample url:  https://localhost:44310/Claims/AddClaim?lang=en <script src="~/lib/jquery/dist/jquery.min.js"></script> <script>     $(document).ready(function () {         $('.btnlang').click(function () {             debugger;             var pageURL = $(location).attr("href");//gets the current url             var baseaddress = pageURL.substring(0, pageURL.indexOf('?'));//get the base address before '?'             var tech = getUrlParameter('lang');//gets the parameter using parameter name i.e,lang             if (tech == "en") {                 location.href = baseaddress + "?lang=ar";             }...

How to write Function to validate input password pattern in mvc using Jquery

 function validatepin(cpin) {     //var paswd = /^(?=.*\d)(?=.*[^a-zA-Z0-9])(?!.*\s).{8,8}$/;     if (containsCharacters(cpin) && containsNumber(cpin) && containsSpecialCharacters(cpin)) {                return true;     } else {                return false;     } } function containsCharacters(val) { var regex = /[A-z]/; var isValid = regex.test(val); return isValid; } function containsNumber(val) { var regex = /[0-9]/; var isValid = regex.test(val); return isValid; } function containsSpecialCharacters(val) { var regex = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/; var isValid = regex.test(val); return isValid; }

How to write api method to Read file and save it in ftp server using webapi c#

[Route("getdata")]         [HttpPost]         public string ReadFromAzureAS(string path)         {             //FTP Server URL.             string ftp = "ftp://localhost:21/";             //FTP Folder name. Leave blank if you want to upload to root folder.             string ftpFolder = "Uploads/";             string status = "File Transfer Failed";             FileStream stream = File.OpenRead(path);             byte[] fileBytes = new byte[stream.Length];             stream.Read(fileBytes, 0, fileBytes.Length);             stream.Close();             //Begins the process of writing the byte array back to a file      ...