从Asp.net查看页面调用Ajax调用返回视图的控制器方法
发布时间:2020-05-25 05:30:51 所属栏目:asp.Net 来源:互联网
导读:我有按钮.我点击按钮时想要路由新视图.按钮如下: button type=button id=btnSearch class=btn btn-warning style=height:35px;width:120px i class=fa fa-search aria-hidden=true/i translateSearch/translate /b
|
我有按钮.我点击按钮时想要路由新视图.按钮如下: <button type="button" id="btnSearch" class="btn btn-warning" style="height:35px;width:120px"> <i class="fa fa-search" aria-hidden="true"></i> <translate>Search</translate> </button> 单击按钮时,以及下面运行的方法: $('#btnSearch').click(function () {
return $.ajax({
url: '@Url.Action("test","ControllerName")',data: { Name: $('#Name').val() },type: 'POST',dataType: 'html'
});
});
我的控制器动作如下: public ActionResult test(string CityName) {
ViewBag.CityName = CityName;
return View();
}
当我调试我的程序时,流程来到我的控制器动作.但索引网页不会路由到测试视图页面.没有发生错误.我能为这个州做些什么? 解决方法如果要刷新页面:控制器: public ActionResult Index()
{
return View();
}
public ViewResult Test()
{
ViewBag.Name = Request["txtName"];
return View();
}
Index.cshtml: @using (Html.BeginForm("Test","Home",FormMethod.Post ))
{
<input type="submit" id="btnSearch" class="btn btn-warning" style="height:35px;width:120px" value="Search"/>
<label>Name:</label><input type="text" id="txtName" name="txtName" />
}
Test.cshtml: @ViewBag.Name ============================================= 如果您不想刷新页面: 控制器: public ActionResult Index()
{
return View();
}
[HttpPost]
public PartialViewResult TestAjax(string Name)
{
ViewBag.Name = Name;
return PartialView();
}
Index.cshtml: <input type="button" id="btnSearch" class="btn btn-warning" style="height:35px;width:120px" value="Search"/>
<label>Name:</label><input type="text" id="txtName" name="txtName" />
<script>
$('#btnSearch').click(function () {
$.ajax({
url: '@Url.Action("TestAjax","Home")',data: { Name: $("#txtName").val() },success: function (data) {
$("#divContent").html(data);
}
});
});
</script>
TestAjax.cshtml: @ViewBag.Name (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET MVC4 Razor模板简易分页效果
- asp.net-mvc – 将Viewmodel数据保存到ASP.NET MVC中的数据
- asp.net-mvc – 在asp.net mvc中启动一组未选中的radiobutt
- asp.net-mvc – 将Castle Windsor与SignalR集成 – 我该如何
- ASP.NET从内存而不是从文件中流内容
- asp.net-mvc-3 – 如何在MVC3上使用authorize属性
- asp.net – 如何配置IIS以接受POST请求?
- asp.net-mvc – 在null模型的情况下返回错误响应
- asp.net – 如何在没有实体框架的MVC中使用SimpleMembershi
- asp.net-core – 将命名空间添加到ASP.NET MVC 6中的所有视
推荐文章
站长推荐
- ASP.NET剃刀参考文档
- asp.net-mvc – 从控制器内部使用Html.ActionLin
- ASP.net页面在import语句中获取错误,但我有参考的
- asp.net-mvc – ASP.NET MVC:获取所有控制器
- asp.net-web-api – 如何从Web API响应中删除标头
- asp.net-mvc – 在自定义Html帮助器中访问模型对
- asp.net – 在web.config下为url重写的多个外部文
- entity-framework – 数据读取器与指定的模型不兼
- ASP.NET中操作SQL数据库(连接字符串的配置及获取
- asp.net-mvc-4 – 为什么ResolveBundleUrl不能用
热点阅读
