TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tangara G
NA
298
93.5k
does not contain a definition for HtmlConvertToJson
Jul 8 2016 3:14 AM
I am getting the below error which I can't find any solution in the internet :<br /><div> </div><div> </div><div>System.Collections.Generic.IEnumerable<>does not contain a definition for 'HtmlConvertToJson and no </div>extension method 'HtmlConvertToJson accepting a first argument of type 'System.Wev.Mvc.HtmlHelper<System.Collections.GenericIEnumerable<> could<br /><div>be found(are you missing a using directive or an assembly</div><div> </div><div>And this is the page where the error occurs at the line <span>new ViewModel(@Html.HtmlConvertToJson(Model)));</span></div><div> </div><div>Hope someone can help me out on this.<br /><div class="dp-highlighter"><ol class="dp-cpp" start="1"><li class="alt"><span><span>@model IEnumerable<BootstrapIntroduction.Models.Author> </span></span></li><li class=""><span> </span></li><li class="alt"><span>@{ </span></li><li class=""><span> ViewBag.Title = <span class="string">"Authors"</span><span>; </span></span></li><li class="alt"><span>} </span></li><li class=""><span> </span></li><li class="alt"><span><h2>Authors</h2> </span></li><li class=""><span> </span></li><li class="alt"><span><p> </span></li><li class=""><span> @Html.ActionLink(<span class="string">"Create New"</span><span>, </span><span class="string">"Create"</span><span>) </span></span></li><li class="alt"><span></p> </span></li><li class=""><span><table <span class="keyword">class</span><span>=</span><span class="string">"table table-bordered table-striped"</span><span>> </span></span></li><li class="alt"><span> <thead> </span></li><li class=""><span> <tr> </span></li><li class="alt"><span> <th>@Html.DisplayNameFor(model => model.FirstName) </th> </span></li><li class=""><span> <th>@Html.DisplayNameFor(model => model.LastName) </th> </span></li><li class="alt"><span> <th>@Html.DisplayNameFor(model => model.Biography) </th> </span></li><li class=""><span> <th>Actions</th> </span></li><li class="alt"><span> </tr> </span></li><li class=""><span> </thead> </span></li><li class="alt"><span> <tbody data-bind=<span class="string">"foreach: authors"</span><span>> </span></span></li><li class=""><span> <tr> </span></li><li class="alt"><span> <td data-bind=<span class="string">"text: FirstName"</span><span>></td> </span></span></li><li class=""><span> <td data-bind=<span class="string">"text: LastName"</span><span>></td> </span></span></li><li class="alt"><span> <td> </span></li><li class=""><span> <a data-bind=<span class="string">"attr {href: '@Url.Action("</span><span>Details</span><span class="string">")/' + Id }"</span><span> </span><span class="keyword">class</span><span>=</span><span class="string">"btn btn-info"</span><span>>Details</a> </span></span></li><li class="alt"><span> <a data-bind=<span class="string">"attr {href: '@Url.Action("</span><span>Edit</span><span class="string">")/' + Id }"</span><span> </span><span class="keyword">class</span><span>=</span><span class="string">"btn btn-primary"</span><span>>Edit</a> </span></span></li><li class=""><span> <a data-bind=<span class="string">"attr: {href: '@Url.Action("</span><span>Delete</span><span class="string">")/' + Id }"</span><span> </span><span class="keyword">class</span><span>=</span><span class="string">"btn btn-danger"</span><span>>Delete</a> </span></span></li><li class="alt"><span> </td> </span></li><li class=""><span> </tr> </span></li><li class="alt"><span></table> </span></li><li class=""><span> </span></li><li class="alt"><span>@section Scripts { </span></li><li class=""><span> <script> </span></li><li class="alt"><span> function ViewModel(authors) { </span></li><li class=""><span> var self = <span class="keyword">this</span><span>; </span></span></li><li class="alt"><span> </span></li><li class=""><span> self.authors = authors; </span></li><li class="alt"><span> }; </span></li><li class=""><span> </span></li><li class="alt"><span> var viewModel = <span class="keyword">new</span><span> ViewModel(@Html.HtmlConvertToJson(Model))); </span></span></li><li class=""><span> ko.applyBindings(viewModel); </span></li><li class="alt"><span> </script> </span></li><li class=""><span>} <br /></span></li></ol></div></div><div>I have added in the necessary library at the HTMLHelperExtension :</div><div> </div><div> <div class="dp-highlighter"><ol class="dp-cpp" start="1"><li class="alt"><span><span class="keyword">using</span><span> BootstrapIntroduction.Models; </span></span></li><li class=""><span><span class="keyword">using</span><span> Newtonsoft.Json; </span></span></li><li class="alt"><span><span class="keyword">using</span><span> System.Web; </span></span></li><li class=""><span><span class="keyword">using</span><span> System.Web.Mvc; </span></span></li><li class="alt"><span> </span></li><li class=""><span><span class="keyword">namespace</span><span> BootstrapIntroduction.HtmlHelperExtension </span></span></li><li class="alt"><span>{ </span></li><li class=""><span> <span class="keyword">public</span><span> </span><span class="keyword">static</span><span> </span><span class="keyword">class</span><span> HtmlHelpherExtensions </span></span></li><li class="alt"><span> { </span></li><li class=""><span> <span class="keyword">public</span><span> </span><span class="keyword">static</span><span> HtmlString HtmlConvertToJson(</span><span class="keyword">this</span><span> HtmlHelper htmlHelper, object model) </span></span></li><li class="alt"><span> { </span></li><li class=""><span> var settings = <span class="keyword">new</span><span> JsonSerializerSettings </span></span></li><li class="alt"><span> { </span></li><li class=""><span> ReferenceLoopHandling = ReferenceLoopHandling.Ignore, </span></li><li class="alt"><span> Formatting = Formatting.Indented </span></li><li class=""><span> }; </span></li><li class="alt"><span> </span></li><li class=""><span> <span class="keyword">return</span><span> </span><span class="keyword">new</span><span> HtmlString(JsonConvert.SerializeObject(model, settings)); </span></span></li><li class="alt"><span> } </span></li><li class=""><span> } </span></li><li class="alt"><span>} <br /></span></li></ol></div></div><div> </div><div> </div><br /><div> </div><div> </div><div> </div><div> </div><div> </div>
Reply
Answers (
2
)
checkbox checked then show text box inside grid view .net
How to implement custom role provider with sitemap nav