从Asp.net查看页面调用Ajax调用返回视图的控制器方法
发布时间:2020-12-15 23:53:39 所属栏目: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 /button 单击按钮时,以及下面运
我有按钮.我点击按钮时想要路由新视图.按钮如下:
<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 app中的会话变量超时
- asp.net – SignalR跨域不在IE10以外的浏览器上工作
- asp.net – global.asax断点未命中
- ASP.NET,C#后台调用前台javascript的五种方法
- asp.net-mvc – 我可以从MVC中的View访问Resources文件吗?
- 当空的asp.net时,ListView LayoutTemplate不显示
- asp.net-mvc – Web Api调用返回404错误,GUID作为参数传递
- 与VS集成的若干种代码生成解决方案[博文汇总(共8篇)]
- linq – 将表达式树从一种类型转换为另一种具有复杂映射的类
- asp.net – 当不匹配路由时,OWIN中的WebApi总是返回200而不
推荐文章
站长推荐
- asp.net – 如何停止所有cassini实例?
- asp.net-mvc – 如何使用app_start或webactivato
- asp.net – 如何在不依赖其扩展名的情况下检查上
- asp-classic – 在VBScript中检查NULL的错误
- asp.net – HTML敏捷包删除break标签关闭
- asp.net – 有关iPhone网站优化的帮助
- asp.net – 如何防止Entity Framework将FileStre
- asp.net – REST服务的成员资格/授权
- asp.net-mvc – ViewBag的重点是什么?
- asp.net-mvc – ASP.net MVC DropDownList预选项
热点阅读