Posts

Showing posts with the label Mvc

How to Read list of objects from json file and convert it into list of objects in c# .net core

  public List<CityMaster> getcities()         {             List<CityMaster> cities = new List<CityMaster>();             try             {                 var res = new List<CityMaster>();                 string path1 = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\assets\citieslist.json"}";                 using (StreamReader r = new StreamReader(path1))                 {                     string json = r.ReadToEnd();                     res = JsonConvert.DeserializeObject<List<CityMaster>>(json);                 }      ...

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;         }