~~~ajax怎么起不了作用?高手们帮忙看看,谢谢
finer 2017-10-31 11:09:06 视图:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
ViewBag.Title = "Ajax应用";
}
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.10.2.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")"></script>
<script type="text/javascript">
function Show(msg) {
alert(msg);
}
</script>
@using (Ajax.BeginForm("Index",
new AjaxOptions() {
HttpMethod = "post",
Url = @Url.Action("Index", "Reviews"),
UpdateTargetId = "listContent",
OnSuccess = "onsuccess"
}))
{
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
@Html.TextBox("username")
<input type="submit" value="Search" class="btn btn-default" />
</div>
</div>
</div>
}
<div id="listContent">
@foreach (var item in ViewData["listname"] as List<string>)
{
<div>@item</div>
}
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication1.Controllers
{
public class AjaxTestController : Controller
{
// GET: AjaxTest
public ActionResult Index(string username)
{
List<string> listname = ShowString(username);
ViewData["listname"]= listname;
return View();
}
public List<string> ShowString(string username)
{
List<string> liststr = new List<string> { "xiao", "Finer", "jacky", "Mimy", "Monico" };
/*
var result = from st in liststr
where st.Contains(username)
select st;*/
//var result = liststr.Where(u=>u==username);
var result = liststr.Where(u => u.Contains(username));
return result.ToList();
}
}
}
ajax没起作用