如何更新我的Html表单而不刷新ASP.net中的页面?

时间:2015-09-17 13:52:01

标签: javascript c# jquery html asp.net-mvc

我试图找到解决方案已经有一段时间没有成功,所以我来这里问。

我有一个ASP.net Web应用程序,我从数据库中获取信息并将该信息放在html页面上的表单中,这很好。我也有一个搜索功能,工作正常。

但每次我搜索它都会重新加载整个页面。我知道我应该使用JQuery ...不知怎的......但我真的不懂如何将它应用到我的代码中。

<div class="tab-content">
    <div id="log" class="tab active">
        <h1>Log</h1>
        @using (Html.BeginForm())
        {
            <p>
                <b>Message:</b> @Html.TextBox("SearchString")
                <input type="button" value="Search" onclick="submit()"/>
            </p>
        }
        @RenderBody()
        @Html.Raw(ViewBag.Data)
    </div>
</div>

1 个答案:

答案 0 :(得分:2)

有很多方法可以做到这一点。 简单的方法是使用普通的jquery函数来更改字段中的数据。 请参阅下面的示例供您参考。

https://dotnetfiddle.net/zIMk99

&#13;
&#13;
function decode(strToDecode) {
  var encoded = strToDecode;
  return unescape(encoded.replace(/\+/g,  " "));
};

function turkGetSubmitToHost() {
      return decode(turkGetParam("turkSubmitTo", "https://www.mturk.com"));
};  

  var form = document.getElementById("mturk_form"); 
  if (form) {
     form.action = turkGetSubmitToHost() + "/mturk/externalSubmit"; 
  } 
&#13;
&#13;
&#13;