weixin_33713350 2014-03-05 10:30 采纳率: 0%
浏览 21

Sitecore 7 MVC 4和Ajax调用

I'm using Sitecore 7.1 and an MVC 4 project.

I'm trying to make a search box which will search news into a bucket and return the result as JSON.

So i read that blog post : http://keeplearningandsharing.wordpress.com/2013/12/13/sitecore-mvc-with-ajax/

and try to do the same but it does not work.

What i did :

1) I created a controller named NewsOverviewController where i put two methods

ActionResult Start() (HttpGet) which return my view with the searchbox
JsonResult Starts(InpurtParams) which perform the search

2) In sitecore, i created my Controller Rendering and add the action start to it.

3) i register a new route in RouteConfig.cs (i put it before the sitecore route and after, didn't change anythings)

  routes.MapRoute(
          name: "search",
          url: "api/NewsOverview/{action}/{id}",
          defaults: new { controller = "NewsOverview", action = "Starts", id = UrlParameter.Optional }
        );

4) I put the following code in my view :

<script>
function getSearchResult() {
    var inputparams = {};
    inputparams.SearchTerm = document.getElementById("searchTerm").value;

    try {
        $.getJSON("/api/NewsOverview/starts", inputparams, displaySearchResult);
    }
    catch (ex) {
        alert("Error : " + ex.message);
    }
}

function displaySearchResult(data) {
    $.each(data, function (i, result) {
        $("#searchresult").append(result.Name + " - " + result.Url + "<br/>");
    });

};
</script>

<div>
    <input type="text" name="searchTerm" id="searchTerm" value="test"/>
    <input type="button" onclick="getSearchResult();"/>
    <div id="searchresult"></div>
</div>

My problem when i try to use the search : He didn't find the url (404 (Page not found) ) : {host}/api/NewsOverview/start?SearchTerm=test

I'm pretty new to MVC, so i miss maybe somethings ...

  • 写回答

2条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?