Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 267643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:35:04+00:00 2026-05-11T23:35:04+00:00

I am trying to implement a feature similar to the Related Questions on StackOverflow,

  • 0

I am trying to implement a feature similar to the Related Questions on StackOverflow, I am doing this in MVC.

$().ready(function() {
   var s = $("#Summary").val();
   $("#Summary").blur(function() { QuestionSuggestions(s); });
});

function GetPastIssues(title) {

$(document).ready(function() {
$.ajax({ type: "POST",
    url: "/Issue/GetSimilarIssues",
    contentType: "application/json; charset=utf-8",
    dataType: "xml",
    dataType: "json",
    data: "{'title':'" + title + "'}",
    processData: false,
    error: function(XMLHttpRequest, textStatus, errorThrown) { ajaxError(XMLHttpRequest, textStatus, errorThrown); },
    success: function(xml) { ajaxFinish(xml); }
  });
});

function ajaxFinish(xml) {
 if (xml.d != "NO DATA") {
    $('#question-suggestions').html(xml.d); //alert(xml.d); // This ALERT IS returning undefined
    $('#question-suggestions').show();
 }
}

The data being returned from my controller is ‘undefined’, as shown by the commented line in ajaxFinish.
What am I doing wrong?

//[AcceptVerbs(HttpVerbs.Get)]
[JsonParamFilter(Param = "title", TargetType = typeof(string))]
public ActionResult GetSimilarIssues(string title)
{
    var issues = _db.GetSimilarIssues(title).ToList();
    if (title == null || issues.Count() == 0)
       return Json("NO DATA");

    string retVal = null;
    foreach (Issue issue in _db.GetSimilarIssues(title))
    {
        retVal += "<div class='answer-summary' style='width: 610px;'>";
        retVal += "<a href='Issue.aspx?projid=" + issue.ProjectId.ToString() + "&issuetypeid=" + issue.IssueTypeId.ToString() +
                "&issueid=" + issue.IssueId.ToString() + "'>";
        retVal += issue.Summary;
        retVal += "</a>";
        retVal += "</div>";
    }
        return Json(retVal);
  }

EDIT:

I think what will help me learn and implement a solution to my senario is if I can get some insight into how StackOverflow implements this javascript method:

function QuestionSuggestions() {
        var s = $("#title").val();            
        if (s.length > 2) {
            document.title = s + " - Stack Overflow";
            $("#question-suggestions").load("/search/titles?like=" + escape(s));
        }

Looks like a ‘Search‘ folder in the Views folder and a PartialView called ‘Title‘. A SearchController.cs with the following method:

public ActionResult titles(string like)
{
   // HOW TO IMPLEMENT THIS
   return PartialView("Titles");
}

What goes in the Titles.ascx to display the html?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:35:05+00:00Added an answer on May 11, 2026 at 11:35 pm

    The purpose of JSON() is to return a JSON object — not HTML. JSON object would be something like {html_value: “<li>blah” }. I’m not sure what your ajax request is expecting. If it is expecting JSON (you have dataType set twice), then you can do something like with an anonymous object:

    return Json(new {html_value = retVal});
    

    However, if you want to return HTML from your controller — don’t. That’s exactly what a view is for. Create a view without any master page and do the loop and return the HTML that way. Ajax apps can take this HTML and drop it wherever necessary.

    In fact, while you technically could do the above anonymous object (where you return the html inside of a json object), this isn’t what it’s for. If you want to use JSON you should be returning values, and letting the javascript on the client format it:

    I’m not sure how “heavy” your issues object is, but assume that it only has the three fields you’re using. In that case, do:

    return Json(issues);
    

    EDIT:

    Well, I think “Best Practice” would be to return just the values via JSON and format within the javascript. I’m not familiar enough with JSON(), but I know it works (I’m using it for something simple). Try creating a simple issues object with just those three values and

    return Json(issuesTxfr);
    

    You don’t need to use partialviews as you’re calling from a controller. Just think of it as a very simple view. Here’s an example of mine (please don’t notice that I’m not following my own JSON advice — this is from a while back and I now cringe looking at it for a few reasons):

        public ActionResult Controls_Search_Ajax(string q, string el)
        {
            ...
    
            ViewData["controls"] = controls;
            ViewData["el"] = el;
    
            return View();
        }
    

    and

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Controls_Search_Ajax.aspx.cs" Inherits="IRSoxCompliance.Views.Edit.Controls_Search_Ajax" %>
    <% var controls = ViewData.Get<IEnumerable<IRSoxCompliance.Models.Control>>("controls");
       var el = ViewData.Get<String>("el");
    
       if (controls != null)
       {
         foreach (var c in controls)
         {
    %><%= c.Control_ID %>***<%= c.Full_Control_Name %>***<li id="<%= el %>:li:<%= c.Control_ID %>"><span class="item"><%= Html.BreadCrumb(c, false) %></span><span class="actions"><a href="#" onclick="sx_Remove_Control('<%= el %>', <%= c.Control_ID %>); return false;">Remove</a></span><br></li>
    <%   }
       }
    %>
    

    Note the fact that there is no master page specified.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a feature similar to the "Related Questions" on Stackoverflow.
I'm trying to implement a feature similar to StackOverflow's tag feature. That a user
I am trying to implement a similar feature like the autosuggest feature for tags
I'm trying to implement an undo/redo feature into my application, using the Command Pattern
I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current
I need to implement a feature similar to the one provided by Microsoft Outlook
How does Wikipedia implement the edit this section feature for its articles, wherein a
I'm trying to find a way to implement file manager functionality in an mvc
All I am currently trying implement something along the lines of dim l_stuff as
trying to implement a dialog-box style behaviour using a separate div section with all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.