jeudi 9 juin 2016

String Display in normal form in mvc Razor

i am new in mvc razor technology. i create one application in which i used html tag i.e DIV which i had given id to it.

i want to add dynamic data to that div in that but it added successfully but i display html tags.

@model Piranha.Models.PageModel
@{
  ViewBag.Title = Model.Page.Title;
  string myData = string.Empty;
  List<Piranha.Entities.Post> posts = null;
  using (var db = new Piranha.DataContext())
  {
    posts = db.Posts.OrderByDescending(p => p.Published).ToList();
  }
 if (posts.Count > 0)
 {
    foreach (var post in posts)
    {
        myData += @Html.Raw(string.Format("<ul class=\"news - list\"><li>  <div class=\"news - wrap\"><span class=\"news - title\"><a href=\"javascript: void(0)\">{0}</a></span><span class=\"news - descr\">{1} </span></div></li>", @post.Title, @post.Description));
    }
}

}

I Used Jquery to bind data

<script type="text/javascript">
$(document).ready(function () {
    $('#MyNews').html("@myData");
});

but unable to display in html for

Aucun commentaire:

Enregistrer un commentaire