Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC4中的谷歌CSE,使用表单时遇到问题_C#_Forms_Asp.net Mvc 4_Post_Google Custom Search - Fatal编程技术网

C# MVC4中的谷歌CSE,使用表单时遇到问题

C# MVC4中的谷歌CSE,使用表单时遇到问题,c#,forms,asp.net-mvc-4,post,google-custom-search,C#,Forms,Asp.net Mvc 4,Post,Google Custom Search,我到处搜索,找不到这个问题的答案,大量的ajax和不相关的链接。请只回答C#MVC(无aspx文件等) 我想使用cshtml上的一个表单将查询读入GoogleCSE,因此我在cse中使用GoogleResultsOnly页面选项。问题是,他们没有指定如何将结果输出到javascript,而大约10年前我只是简单地做了js,我不知道如何做,需要一些帮助 我想将我的查询发送到搜索控制器,然后搜索控制器生成包含谷歌结果的页面。google javascript在布局页面中列出 标题cshtml文件,其

我到处搜索,找不到这个问题的答案,大量的ajax和不相关的链接。请只回答C#MVC(无aspx文件等)

我想使用cshtml上的一个表单将查询读入GoogleCSE,因此我在cse中使用GoogleResultsOnly页面选项。问题是,他们没有指定如何将结果输出到javascript,而大约10年前我只是简单地做了js,我不知道如何做,需要一些帮助

我想将我的查询发送到搜索控制器,然后搜索控制器生成包含谷歌结果的页面。google javascript在布局页面中列出

标题cshtml文件,其中包含谷歌搜索

搜索页面.cshtml


弄清楚发生了什么:
在我的声明中,我应该使用method=“get”而不是method post,我应该在SearchController中的函数之前声明[HttpGet],而不是[HttpPost],代码现在可以正常工作。

在控制器中,程序需要[HttpGet]而不是[HttpPost],并且不需要任何变量(正如js处理的那样)

在header.cshtml中,表单的第一行需要从method=“post”更改为method=“get”



希望这对MVC和CSE集成方面的其他人有所帮助。

刚刚发现我应该使用HttpGet而不是HttpPost调用
<form class="navbar-form  input-group-sm btn-group" gname="gsearch" role="search" method="post" action="@Url.Action("Index", "Search")">
            <div class="navbar-form input-group-addon input-group-sm btn-group-sm" style="background-color:transparent">
                <input class="form-control" name="q" size="20" style="vertical-align:bottom;margin:0px;padding:0px" maxlength="255" value="search site" onclick="value = '';" />
                <button class="btn btn-default btn-sm" type="submit" style="margin:0px"><i class="glyphicon glyphicon-search" style="margin:0px;"></i></button>
            </div>
        </form>
public class SearchController : Controller
{

    //
    // GET: /Search/
    [HttpPost]
    public ActionResult Index(string q)
    {
        return View();
    }
}
<div class="gcse-searchresults" >
<gcse:searchresults-only linkTarget="_top" gname="gsearch"></gcse:searchresults-only>
[HttpGet]
    public ActionResult Index()
    {
        return View();
    }
<form class="navbar-form  input-group-sm btn-group" gname="gsearch" role="search" method="get" action="@Url.Action("Index", "Search")">