ASP.NET MVC - Rewritting FormMethod.Get查询字符串? [英] ASP.NET MVC - Rewritting FormMethod.Get querystring?

查看:128
本文介绍了ASP.NET MVC - Rewritting FormMethod.Get查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表格只有一个文本框,一个提交按钮。形式基本上发送到不同的页面,在文本框中作为查询字符串值。当我点击提交按钮,查询字符串就是这种格式,例如:

I have a simple form with just one textbox and one submit button. The form basically sends to a different page with the value in the textbox as querystring. When I click on the submit button, the querystring is in this format, for example:

mysite.com/?TargetCode=Test1

我想它以这种格式显示: mysite.com/Test1

我已经在我的行动的HomeController 即走目标code作为查询字符串,而我已经设置了路由 Global.ascx.cs 为。我应该怎么做,因此不会有重新编写的查询字符串?目标code =的网址是什么?这里是code,因为我有以下形式:

I already have an Action in my HomeController that take the "TargetCode" as the querystring, and I've already setup a routing in the Global.ascx.cs for that. What should I do to re-write the querystring so it doesn't have that "?TargetCode=" in the URL? Here is the code for the form I have:

<% using (Html.BeginForm("Index", "Home", FormMethod.Get, new { id = "CodeForm" }))

谢谢,
肯尼。

Thanks, Kenny.

推荐答案

我认为你必须使用jQuery做提交,否则你是依赖于浏览器如何构建URL。 更新以包括勾入验证插件。

I think you'd have to use jQuery to do the submission otherwise you're dependent on how the browser constructs the URL. Updated to include a hook into the validation plugin.

$('#CodeForm').submit( function() {
     var $form = $(this);
     if ($form.valid()) {
        window.location.href = $form.attr('action')
                                  + '/'
                                  + $('[name=TargetCode]').val();
     }
     return false;
});

这篇关于ASP.NET MVC - Rewritting FormMethod.Get查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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