C# 重定向到ActionResult的HTML图像按钮

C# 重定向到ActionResult的HTML图像按钮,c#,html,asp.net-mvc,visual-studio-2010,C#,Html,Asp.net Mvc,Visual Studio 2010,在一个MVC项目中,我试图创建一个HTML图像按钮,该按钮将重定向到ActionResult。 这是一个搜索框 目前,我只有这样的想法: <input type="text" id="Text1" name="seachKeyword" class="searchTextBox" value="Search" style="color:blue; " onfocus="this.value==this.defaultValue?this.value='':null"/> 在这种情况

在一个MVC项目中,我试图创建一个HTML图像按钮,该按钮将重定向到ActionResult。 这是一个搜索框

目前,我只有这样的想法:

<input type="text" id="Text1" name="seachKeyword" class="searchTextBox" value="Search" style="color:blue; " onfocus="this.value==this.defaultValue?this.value='':null"/>

在这种情况下使用表单在语义上更为正确:

@using(Html.BeginForm("Search", "Something"))
{
    <input type="text" id="Text1" name="keyword" class="searchTextBox" value="Search" style="color:blue;" onfocus="this.value==this.defaultValue?this.value='':null"/>
    <input type="image" src="somesrc" width="100" height="100" class="aaa" value="something" alt="something" />
}

感谢您的帮助:)现在它看起来就像您的示例(第一个),但是我的“搜索”看起来像:public ActionResult Search(string关键字){…},而“关键字”是文本框值。那么,我如何将它传递到这里/从这里访问它?tnx@user990635,如果您决定按照我的建议使用表单,那么您只需输入文本即可。如果您决定使用一个锚点来使用javascript,那么您应该简单地使用
关键字
作为查询字符串参数:
window.location.href=href+'keyword='+encodeURIComponent(关键字)。我已经更新了我的答案。我使用了你的建议。很好用!谢谢
<a href="somehow redirect to the search controller with the textbox value">
<img src="somesrc" alt="something" width="100" height="100" />
</a>
[HttpPost]
public ActionResult Index(string id)
{
    return RedirectToAction("Search", "Something", new { keyword = id, pageNumber = 1 });
}
@using(Html.BeginForm("Search", "Something"))
{
    <input type="text" id="Text1" name="keyword" class="searchTextBox" value="Search" style="color:blue;" onfocus="this.value==this.defaultValue?this.value='':null"/>
    <input type="image" src="somesrc" width="100" height="100" class="aaa" value="something" alt="something" />
}
$(function() {
    $('#id_of_anchor').click(function() {
        var keyword = $('#id_of_search_textbox').val();
        var href = this.href;
        if (href.indexOf('?') > -1) {
            href += '&';
        } else {
            href += '?';
        }
        window.location.href = href + 'keyword=' + encodeURIComponent(keyword);
        return false;
    });
});