如何访问ASP.NET MVC AJAX哈希值? [英] How to access AJAX hash values in ASP.NET MVC?

查看:118
本文介绍了如何访问ASP.NET MVC AJAX哈希值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用散列方法来创建静态URL内容由在Asp.Net MVC Ajax调用管理。概念我工作的证明个人资料页 /用户/配置文件,其中一个可以浏览和编辑不同的部分。你总是可以问以下网址 /用户/ profile文件#密码来直接访问你的个人资料页,在更改密码栏目

I'm considering using the hash method to create static urls to content that is managed by ajax calls in a Asp.Net MVC. The proof of concept i'm working on is a profile page /user/profile where one can browse and edit different sections. You could always ask for the following url /user/profile#password to access directly to you profile page, in the change password section

不过,我想知道,如果我不是在开始这个坏的方法,因为很明显我不能散后,由<$ C $宣布哈希的路由值进入部分以任何方式,除非C>的Global.asax 。所以我想知道如果这是正确的方式来访问这部分URL的?

However, i'm wondering if i'm not starting this the bad way, since apparently i can't access the part after the hash in any way, except by declaring a route value for the hash in global.asax. So i'm wondering if this is the right way to access this part of the url?

我应该申报路线值,或者是有另一种方式与哈希值(一个框架,JavaScript或MVC)?

Am i supposed to declare a route value, or is there another way to work with hash values (a framework, javascript or mvc)?

编辑补充: 在纯JavaScript,我必须使用 window.location.hash 特性没有问题,我不知道,虽然这是在当今的浏览器如何使用标准,因此关于一个JavaScript的问题框架/插件,会使用它。

Edited to add: In pure javascript, i have no problem using the window.location.hash property, i'm not sure though how standard it is in today's browsers, hence the question about a javascript framework/plugin that would use it.

推荐答案

的事情是,后面的散列(#)的部分永远不会发送到服务器到HTTP请求,这样服务器完全没有办法阅读它。因此,没有必要浪费时间寻找不存在的东西。

The thing is that the part that follows the hash (#) is never sent to the server into the HTTP request so the server has absolutely no way of reading it. So no need to waste time in searching for something that doesn't exist.

您可以从另一方面调整你的路线生成包含散列部分的链接,以便客户端脚本可以读取它。

You could on the other hand tune your routes to generate links that contain the hash part so that client scripts can read it.

这篇关于如何访问ASP.NET MVC AJAX哈希值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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