方法调用 Controller的Action 参数
2017-03-30 12:18
399 查看
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;namespace WebProjects.Controllers{ public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { return View(); } [HttpGet] public ActionResult Login() { string loginUser = Request.QueryString["usercode"]; string pwd = Request.QueryString["pwd"]; if (loginUser == "admin" && pwd == "111") { return Json(new { success = true, msg = "登录成功" }, JsonRequestBehavior.AllowGet); } else { return Json(new { success = false, msg = "登录失败" }, JsonRequestBehavior.AllowGet); } } public ActionResult Admin(string usercode) { //根据usercode查询出密码pwd string pwd = "111"; return RedirectToAction("Login", "Home", new { usercode = usercode, pwd = pwd }); } }}
@{ Layout = null;}<!DOCTYPE html><html><head> <meta name="viewport" content="width=device-width" /> <title>首页</title> <script src="~/Scripts/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(function () { $('#btnlogin').click(function () { var usercode = $('#usercode').val(); var pwd = $('#pwd').val(); $.ajax({ type: "Get", url: "../Home/Login?usercode=" + usercode + "&pwd=" + pwd, dataType: "json", success: function (data) { alert(data.msg); } }); }); }); </script></head><body> <div> 用户名:<input type="text" id="usercode" /> </div> <div> 密码:<input type="password" id="pwd" /> </div> <div> <input type="button" value="登录" id="btnlogin" /> </div></body></html>
@{ Layout = null;}<!DOCTYPE html><html><head> <meta name="viewport" content="width=device-width" /> <title>首页</title> <script src="~/Scripts/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(function () { $('#btnlogin').click(function () { var usercode = $('#usercode').val(); var pwd = $('#pwd').val(); $.ajax({ type: "Get", url: "../Home/Login?usercode=" + usercode + "&pwd=" + pwd, dataType: "json", success: function (data) { alert(data.msg); } }); }); }); </script></head><body> <div> 用户名:<input type="text" id="usercode" /> </div> <div> 密码:<input type="password" id="pwd" /> </div> <div> <input type="button" value="登录" id="btnlogin" /> </div></body></html>
相关文章推荐
- 找到多个与名为“HOME”的控制器匹配的类型。如果为此请求(“{CONTROLLER}/{ACTION}/{ID}”)提供服务的路由在搜索匹配此请求的控制器时没有指定命名空间,则会发生此情况。如果是这样,请通过调用含有“NAMESPACES”参数的“MAPROUTE”方法的重载来注册此路由。
- struts 页面调用Action的指定方法并传递参数
- 笔记01 登录、常用配置参数、Action访问Servlet API 和设置Action中对象的值、命名空间和乱码处理、Action中包含多个方法如何调用
- Struts2 ognl调用action有参数的方法
- 使用<a>标签调用struts2的action、传递动态参数、以及参数中出现加号等特殊字符的处理方法
- struts2 笔记01 登录、常用配置参数、Action访问Servlet API 和设置Action中对象的值、命名空间和乱码处理、Action中包含多个方法如何调用
- Struts2学习---基本配置,action,动态方法调用,action接收参数
- Struts2学习---基本配置,action,动态方法调用,action接收参数
- Struts2 ognl调用action有参数的方法
- springmvc中参数绑定pojo绑定,同个controller的不同方法调用,后一个方法的形参取到request域中的值为null
- (不推荐使用)springMVC基本配置+继承MultiActionController来实现根据参数名指定要请求的方法
- 解析请求参数调用Action中的方法的struts1.x完整实例
- Struts2调用Action的两种方法以及参数处理
- MVC3.0 不同view层,调用相同Controller方法,但参数不同
- C#线程调用带参数的方法
- 实体类的调用webservice 方法里面有多个参数
- 理解 Delphi 的类(十) - 深入方法[3] - 调用时参数分割
- JS调用后台带参数的方法
- JS调用后台带参数的方法
- C#线程调用带参数的方法