如何在MVC4中隐藏URL参数 [英] How to Hide Parameters of URL in MVC4
问题描述
http://localhost:49397/ChildCare/SponsorChild/83
这是链接,当我单击表中的操作链接并重定向到编辑操作"时会生成该链接,现在我想在URL中隐藏数字"83",我该如何做到这一点,
This is the Link ,which is being generated when i click on action link in table and redirecting to Edit Action, now i want to Hide the number '83' in the URL how can i acheive this,
我正在使用VS2010 MVc4剃须刀, 对不起,我的英语不好 预先感谢
i am using VS2010 MVc4 Razor, Sorry for my bad engllish thanks in advance
推荐答案
如果使用链接,则GET
请求将链接发送到服务器,则参数位于url中.可能您有两个选择:
if you work with links, the links send by GET
request to the server, then the parameters are in the url. Might you have two options:
1-参数必须位于data
属性(如data-id="83"
)上,然后创建一个表单以通过邮寄发送数据,并创建具有属性data-x
的标签input
,例如:
1 - the parameters would have to be on data
attributes like data-id="83"
and then create a form to send data by post, and creating tags input
with attributes data-x
, for example:
<a href="my/url" data-id="83> link </a>
然后使用javascript,您需要创建以下表单:
then with javascript you need create the form:
<form method="POST" action="my/url">
<input value="83 name="id" type="hidden" />
</form>
并使用JS表单提交运行事件,例如:jQuery('form').submit()
and run the event with JS form submit like: jQuery('form').submit()
2-您可以在控制器中加密然后解密get参数:如何在MVC中加密和解密数据?
2 - you can encrypt and then decrypt get parameters in the controller: How to encrypt and decrypt data in MVC?
修改
第一点示例:
HTML:
<div id="container-generic-form" style="display:none;">
<form action="" method="POST"></form>
</div>
<a href="my/url" data-id="83" data-other="blue" class="link-method-post">my link</a>
JS:
$(function() { // document ready
var controlAnchorClickPost = function(event) {
event.preventDefault(); // the default action of the event will not be triggered
var data = $(this).data(),
form = $('#container-generic-form').find('form');
for(var i in data) {
var input = $('<input />', {
type: 'hidden',
name: i
}).val(data[i]);
input.appendTo(form);
}
form.submit();
};
$('a.link-method-post').on('click', controlAnchorClickPost); //jquery 1.7
});
这篇关于如何在MVC4中隐藏URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!