Gow*_*ham 4 asp.net-mvc asp.net-mvc-routing
http://localhost:49397/ChildCare/SponsorChild/83
这是链接,当我点击表格中的动作链接并重定向到编辑动作时生成链接,现在我想隐藏URL中的数字'83'我该如何实现这一点,
我正在使用VS2010 MVc4 Razor,对不起,我提前做了一个糟糕的英特尔谢谢
如果你使用链接,链接通过GET请求发送到服务器,然后参数在URL中.你有两个选择:
1 - 参数必须在data属性上data-id="83",然后创建一个表单以通过post发送数据,并创建input带有属性的标签data-x,例如:
<a href="my/url" data-id="83> link </a>
Run Code Online (Sandbox Code Playgroud)
然后用javascript你需要创建表单:
<form method="POST" action="my/url">
<input value="83 name="id" type="hidden" />
</form>
Run Code Online (Sandbox Code Playgroud)
并使用JS表单提交运行事件,如: jQuery('form').submit()
2 - 您可以在控制器中加密然后解密获取参数:如何在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>
Run Code Online (Sandbox Code Playgroud)
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
});
Run Code Online (Sandbox Code Playgroud)
我们使用两个这样的页面来隐藏变量
public ActionResult RestoreSavedSession(string id)
{
Session["RestoreSavedSession"] = id;
return RedirectToAction("RestoreSavedSessionValidation");
}
public ActionResult RestoreSavedSessionValidation()
{
return View("RestoreSavedSessionValidation");
}
Run Code Online (Sandbox Code Playgroud)
您点击RestoreSavedSession它然后将参数存储在本地并调用RestoreSavedSessionValidation它从会话或缓存或其他任何读取参数的位置。
| 归档时间: |
|
| 查看次数: |
19007 次 |
| 最近记录: |