首页 新闻 赞助 找找看

在mvc中使用telerik控件在视图中显示grid控件时出现the requesed url returned 12030-unknown

0
悬赏园豆:80 [已解决问题] 解决于 2012-02-11 16:19

其中对数据库访问封装的方法为: public class IPLibManager
    {
        /// <summary>
        /// 获取SystemConfig表的所有属性并链表形式返回视图
        /// </summary>
        /// <returns></returns>
        public static IList<SystemConfig> All()
        {
            Entities entities = new Entities();
            IList<SystemConfig> result=(IList<SystemConfig>)HttpContext.Current.Session["systemConfig"];
            if (result == null)
            {
                HttpContext.Current.Session["systemConfig"]=result=
                    (from systemConfig in entities.SystemConfig
                         select new SystemConfig
                         {
                             ParameterId=systemConfig.ParameterId,
                             ParameterGroup=systemConfig.ParameterGroup,
                             ParameterName=systemConfig.ParameterName,
                             ParameterValue=systemConfig.ParameterValue
                         }).ToList();                   
            }
            return result;
        }
        /// <summary>
        /// 插入一条数据
        /// </summary>
        /// <param name="systemConfig"></param>
        public static void Insert(SystemConfig systemConfig)
        {
            systemConfig.ParameterId=All().OrderByDescending(c => c.ParameterId).First().ParameterId + 1;
            All().Insert(0,systemConfig);
        }
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="systemConfig"></param>
        public static void Update(int id)
        {
            Entities entities = new Entities();
            var target = from sc in entities.SystemConfig
                         where sc.ParameterId == id
                         select sc;
            if (target != null)
            {
                entities.SaveChanges();
            }
           
        }
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="id"></param>
        public static void Delete(int id)
        {
            Entities entities=new Entities();
            var target = from sc in entities.SystemConfig
                         where sc.ParameterId == id
                         select sc;
            if (target != null)
            {
                entities.SystemConfig.DeleteObject(target.First());
                entities.SaveChanges();
            }
        }
    }

controller为:public ActionResult IPLib()
        {
            return View();
        }
        [GridAction]
        public ActionResult _SelectIPLib()
        {
            return View(new GridModel(IPLibManager.All()));
        }
        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveIPLib(int id)
        {
            return View();
        }
        [HttpPost]
        [GridAction]
        public ActionResult _InsertIPLib()
        {
            SystemConfig systemConfig = new SystemConfig();
            if (TryUpdateModel(entities.SystemConfig))
            {
                IPLibManager.Insert(systemConfig);
            }
            return View(new GridModel(IPLibManager.All()));
        }
        [HttpPost]
        [GridAction]
        public ActionResult _DeleteIPLib(int id)
        {
            var result = from sc in entities.SystemConfig
                         where sc.ParameterId == id
                         select sc;
            if (result != null)
            {
                entities.SystemConfig.DeleteObject(result.First());
                entities.SaveChanges();
            }
            return View(new GridModel(IPLibManager.All()));
        }

view为:

@{
    ViewBag.Title = "IPLib";
}


@(Html.Telerik().Grid<IISTelerikMvc.Models.SystemConfig>()
.Name("Grid").DataKeys(keys =>
{
    keys.Add(sc => sc.ParameterId);
}).ToolBar(commands => commands.Insert().ImageHtmlAttributes(new { style = "margin-left:0" }))
.DataBinding(dataBinding =>
{
    dataBinding.Ajax()
        .Select("_SelectIPLib", "Grid")
        .Insert("_InsertIPLib", "Grid")
        .Update("_SaveIPLib", "Grid")
        .Delete("_DeleteIPLib", "Grid");
})
.Columns(colmns =>
{
    colmns.Bound(sc => sc.ParameterName).Width(150);
    colmns.Bound(sc => sc.ParameterGroup).Width(150);
    colmns.Bound(sc => sc.ParameterValue).Width(150);
    colmns.Bound(sc => sc.Other1).Width(150);
    colmns.Command(commands =>
        {
            commands.Edit();
            commands.Delete();
        })
        .Width(150).Title("Commands");
}).Pageable().Scrollable().Sortable()
)

问题是这样操作之后再也面中点击跳转这个视图时出现the requesed url returned 12030-unknown,有没有大虾现在正在用这个出现过这个问题,困扰2天了,求救求解啊。。。

路遥天的主页 路遥天 | 初学一级 | 园豆:111
提问于:2012-02-08 09:45
< >
分享
最佳答案
1

你所的跳转是什么意思,是从其它页面跳转到此页面?如果是出现这样的错误应该是Grid请求不到你的Controller,在FireFox下调试,打开控制台,看看是哪个URL出了问题,然后在具体的看,问题应该出在路由上,看看你是不是分区域了,注册路由是不是使用了命名空间,检查下这些问题,基本就能排除了。希望对你有帮助。

收获园豆:80
水晶途途 | 小虾三级 |园豆:1443 | 2012-02-11 16:05

谢谢了 ,问题已经解决了,虽然你说的有些地方我不是很明白,但是你的思路感觉有用。顺便能问下么,为啥grid控件在执行delete时没有把参数传过去,很郁闷,添加和更新都没有问题。。

路遥天 | 园豆:111 (初学一级) | 2012-02-11 16:19

@路遥天: Controller里面_DeleteIPLib(int id),这里的参数是int,而通过url传值过去得到的应该是字符串,不会根据你定义的类型自动转换的,所以你接受不到参数,保存调用的Action应该也会出现这样的情况。

水晶途途 | 园豆:1443 (小虾三级) | 2012-02-11 16:57

@路遥天: 我这边也出现了,你怎么搞定的,在线等待............................

Jolan | 园豆:171 (初学一级) | 2012-04-21 19:57

@我心畅想: 把你的代码贴出来看看了。

水晶途途 | 园豆:1443 (小虾三级) | 2012-04-23 09:58
其他回答(1)
0

 columns.Bound(sample => sample.OwerName).Width(80).Title("所属人").Sortable(false).HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:center" });                    

 columns.Template(@<text></text>)

.ClientTemplate("<a href='javascript:' title='详情' onclick='Details(<#= Id #>);' ><img src='/Themes/default/images/03.png' alt='详情'/></a>")

                        .HeaderTemplate(@<text>操作</text>).Width(95)                         .HeaderHtmlAttributes(new { style = "text-align:center" });

 

这样跳转....

旋转 | 园豆:187 (初学一级) | 2012-02-08 10:52

没看太明白啊,能加些解释么。

支持(0) 反对(0) 路遥天 | 园豆:111 (初学一级) | 2012-02-08 10:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册