首页 新闻 会员 周边

mvc的问题 初学者 大侠们路过的帮帮忙吧

0
悬赏园豆:20 [已解决问题] 解决于 2012-07-18 14:34

看图片:首先说下业务逻辑 左边是菜单 点击对应的选项过滤右边的数据 :文本框输入文字查询显示对应的菜单: 下面还有个分页:

现在的问题是我点击查询后地址栏变:http://localhost:7815/WC_Index/Jquery

WC_Index是控制器 query控制器对应的方法(视图)这个估计大侠们都知道我就不多说了?

然后我点分页 地址 :http://localhost:7815/WC_Index/Jquery?ObjectID=6

实际上正确的地址应该是:http://localhost:7815/WC_Index/?ObjectID=6(没有Jquery)

而其他的操作都是正常的 原因我也知道了我在提交表单定义视图的时候加 了 这个如图:

所以路劲是这个样子。请问有什么办法解决呢?

我把控制器的代码发出来 大侠们帮帮我 我才学习一个星期就搞实战 难免会问好多低级的问题 谢谢!

View Code
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Web;
  5 using System.Web.Mvc;
  6 using System.Web.Routing;
  7 using WC_DBConsole.Models.DaoInterface;
  8 using System.Data;
  9 using WC_DBConsole.Models;
 10 using MvcHelper;
 11 using Webdiyer.WebControls.Mvc;
 12 
 13 namespace WC_DBConsole.Controllers
 14 {
 15     public class WC_IndexController : Controller
 16     {
 17         /// <summary>
 18         /// 页面菜单 显示数据 分页集合
 19         /// </summary>
 20         public class unite
 21         {
 22             public DataTable menu = new DataTable();
 23             public DataTable dt = new DataTable();
 24             public PagedList<DataRow> pl;
 25 
 26             public IList<DbCon_view> list = new List<DbCon_view>();//null
 27         }
 28 
 29         /// <summary>
 30         /// 接口ICustomerInfoModel
 31         /// </summary>
 32         public WC_DBConsole.Models.ICustomerInfoModel CustomerInfo { get; set; }
 33 
 34         protected override void Initialize(RequestContext requestContext)
 35         {
 36             if (CustomerInfo == null)
 37             {
 38                 CustomerInfo = new DaoCustomerInfoModel();
 39             }
 40             base.Initialize(requestContext);
 41         }
 42 
 43         [HttpPost]
 44         public ActionResult Jquery(FormCollection fc,int? ObjectID = 1)//查询的控制器方法
 45         {
 46             unite query = new unite();
 47             string txtName = fc["txtName"];
 48             query.menu = CustomerInfo.GetMeanList(txtName).Tables[0];
 49             query.dt = CustomerInfo.GetDtList(-0).Tables[0];
 50             int pageSize = 20;
 51             int pageIndex = ObjectID ?? 1;
 52             query.pl = new PagedList<DataRow>(query.dt.Select(), pageIndex, pageSize);
 53 
 54             return View("Index", query);
 55         }
 56 
 57         public ActionResult Index(int? ObjectID = 1)//页面默认进来加载的显示
 58         {
 59             unite un = new unite();
 60             un.menu = CustomerInfo.GetMeanList().Tables[0];
 61   
 62 
 63             un.dt = CustomerInfo.GetDtList(-0).Tables[0];
 64             int pageSize = 20;
 65             int pageIndex = ObjectID ?? 1;
 66             un.pl = new PagedList<DataRow>(un.dt.Select(), pageIndex, pageSize);  
 67      
 68             return View(un);
 69         }
 70 
 71         public ActionResult UrlJquery(int id, int? ObjectID=1)//点击菜单栏加载右边对应的数据
 72         {
 73             unite un = new unite();
 74             un.menu = CustomerInfo.GetMeanList().Tables[0];
 75 
 76 
 77             un.dt = CustomerInfo.GetDtList(id).Tables[0];
 78             int pageSize = 20;
 79             int pageIndex = ObjectID ?? 1;
 80             un.pl = new PagedList<DataRow>(un.dt.Select(), pageIndex, pageSize);
 81 
 82             return View("Index", un);
 83         }
 84 
 85         public ActionResult Meau()
 86         {
 87             DataTable dt = CustomerInfo.GetMeanList().Tables[0];
 88             if (dt.Rows.Count > 0)
 89             {
 90                 return View(dt);
 91             }
 92             return View("Index");
 93         }
 94 
 95         public ActionResult AddCustomer()
 96         {
 97             string str = "你好啊!怎么还没有反应呢?你明白我的意思不";
 98             ViewBag.txt = str;
 99             return View();
100         }
101 
102         public ActionResult AddVehicle()
103         {
104             A_CustomerInfoModel cuInfo = new A_CustomerInfoModel();
105             cuInfo.A_Customer_Name = "t_sp 总有人说t_sp明白不规范可谁知道呢 呵呵";
106             return View(cuInfo);
107         }
108     }
109 }

(代码我随便写了点中文注释)  还有这里有个不好的地方 代码冗余 特别是那个类 还有就是每一次我操作一下我都把所有的结果集都返回去了 这样性能和逻辑思维上也不合理 ,MVC有什么办法解决这个问题吗?

在一次感谢哥哥姐姐们的阅读 帮帮小弟想个法子?

s_p的主页 s_p | 初学一级 | 园豆:138
提问于:2012-07-17 18:19
< >
分享
最佳答案
0

我个人的经验是把要查询的keywords传递回index,而不会新建一个action去处理。

收获园豆:20
Joe Hou | 菜鸟二级 |园豆:265 | 2012-07-18 10:08

我昨天晚上也想了下 也觉得这样我在

  public ActionResult Index(string name,int? ObjectID = 1)

控制器默认的方法上在加一个参数 对 了 我的路由怎么改啊

 routes.MapRoute(
                "Default", // 路由名称
                "{controller}/{action}/{id}", // 带有参数的 URL
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
            );

这个name参数可以是空 因为默认进来的时候没有参数的 .

还没写过呢 大侠 就知道他是怎么回事 帮帮忙。

s_p | 园豆:138 (初学一级) | 2012-07-18 11:19

@s_p: 我自己知道了 谢谢 我网上查一下就好了 呵呵

s_p | 园豆:138 (初学一级) | 2012-07-18 11:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册