使用MVC,jquery进行导航 [英] Navigating using MVC, jquery

查看:67
本文介绍了使用MVC,jquery进行导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有一个屏幕,其顶部有一个会计期间下拉菜单,当它被更改时,它应该将我重定向到同一个屏幕,但选择的年份。



问题:我在该视图上上传了功能。上传功能调用post方法说actionmethod1,屏幕来自actionmethod2。因此,当我上传url是/ actionmethod1时,当我选择下拉列表时,它会采取最后一个调用的操作方法,即actionmethod1,并看到它因为找不到资源而抛出错误。



用于在jquery中重定向的代码:

Hello,

I have a screen where at top it has a fiscal period dropdown and when changed it should redirect me to same screen but for the year selected.

Issue : I have upload functionality on that view. upload functionality calls the post method say "actionmethod1" and the screen comes from "actionmethod2". so when i do upload the url is /actionmethod1 and when i select dropdown it will take to last action method invoked i.e actionmethod1 and saw it throws error as resource not found.

code being used for redirecting in jquery :

@HttpContext.Current.Request.RequestContext.RouteData.



它调用上传的post action方法和抛出一个错误。





我们使用的是剑道上传功能,使用


it calls the post action method of upload and throws an error.


we are using kendo upload functionality which uses

form method="post" action='@Url.Action("Upload", "controllername")'>



所以如何使用actionname导航同一个屏幕屏幕



我尝试过:



我正在尝试使用UrlReferrer方法获取父级或更早的action方法和控制器名称,以便它将我带到相同的视图。



问题是



1)我无法检查request.urlReferrer上是否存在。它总是失败




so how to navigate the same screen using actionname of the screen

What I have tried:

I am trying to use UrlReferrer method to get parent or earlier actionmethod and controller name so that it takes me to same view.

issue is

1) i am unable to check if exists on request.urlReferrer. It is failing always

if(Request.UrlReferrer !== null)   
                    {
                        var path = @HttpContext.Current.Request.UrlReferrer.LocalPath.ToString();
                    }

But for some reason even for null UrlReferrer it is satifying if condition and getting null exception error.





2.使用urlReferrer是好的,因为它是客户端。还有其他建议提供如何导航..



谢谢



2. Is it good to use urlReferrer as it is client side. Are there any other suggestions providing how to navigate through..

Thank you

推荐答案

我解决了将viewdata.modelstate存储在tempdata中,并在重定向到同一视图时从tempdata再次恢复它。我创建了动作过滤器,用于设置tempdata并从tempdata恢复以获得可重用性。



以下两个链接帮助我:





什么是ModelState? - ASP.NET MVC揭秘 [ ^ ]



Jef Claes:使用PRG时保持模型状态 [ ^ ]
I resolved by storing the viewdata.modelstate in tempdata and restoring it again from tempdata while redirecting to same view. I created action filter for setting tempdata and restoring from tempdata for reusability.

Below two links helped me :


What is the ModelState? - ASP.NET MVC Demystified[^]

Jef Claes: Persisting model state when using PRG[^]


这篇关于使用MVC,jquery进行导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆