Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We had to solve a similar issue, but instead of using an HTML form we opted for a JavaScript based solution that posts a message to an API controller.</p> <p>Detail.aspx</p> <pre><code>&lt;!-- Display the Content (i.e. News Story, Product, etc --&gt; &lt;%= Html.DisplayFor(n =&gt; Model.Content[Model.Content.PageIndex], "ReleaseFull")%&gt; &lt;!-- Display the comments and form. Pass in the type of content and the Id --&gt; &lt;% Html.RenderAction("Commenting", "Home", new { area = "Reviews", contentTypeName = "product", contentTypeId = ContentType.Product, contentId = Model.Content[Model.Content.PageIndex].Id }); %&gt; </code></pre> <p>Commenting Controller</p> <pre><code>[ChildActionOnly] public ActionResult Commenting(string contentTypeName, int contentTypeId, int contentId) { //psuedo-code to get comments var comments = CommentingAPI.GetCommentsForContentType(contentTypeId, contentId); var viewModel = new CommentsListing { Comments = comments, ContentId = contentId, ContentTypeId = contentTypeId, ContentTypeName = contentTypeName }; return View(viewModel); } </code></pre> <p>Commenting.aspx</p> <pre><code>&lt;%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage&lt;Website.ViewModels.CommentsListing&gt;" %&gt; &lt;div id="commenting" class="commenting"&gt; &lt;h3 class="h2"&gt;Comment and then share on Facebook &amp;amp; Twitter&lt;/h3&gt; &lt;div class="arrow"&gt;&lt;/div&gt; &lt;textarea placeholder="Type your comment here..." class="w100 p10 tMrg10" cols="40" rows="4" id="commentText&gt;&lt;/textarea&gt; &lt;div class="textarea-support"&gt; &lt;span class="post-action"&gt; &lt;span id="commentButton"&gt;&lt;a class="btn l-btn-lg"&gt;Post Comment&lt;/a&gt;&lt;/span&gt; &lt;/span&gt; &lt;/div&gt; &lt;!-- Insert new comments here so they show up at the top of the listing --&gt; &lt;div id="newComments"&gt;&lt;/div&gt; &lt;% foreach (var comment in Model.Comments) { %&gt; &lt;!-- Display the comments here --&gt; &lt;% var memberComment = comment; %&gt;&lt;%= Html.DisplayFor(c =&gt; memberComment)%&gt; &lt;% } %&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; //using a custom jQuery plugin we hook up the commenting section //when the user clicks "Post Comment" the message is posted to //another Controller using $.ajax({ type:POST }); //The controller stores the comment in the database and returns an instance of the comment $(function () { $('#commenting').commenting( { contentTypeTypeId: &lt;%: Model.ContentTypeId %&gt;, contentId: &lt;%: Model.ContentId %&gt;, isAuthenticated: &lt;%= Html.IsMember() %&gt; }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload