English 中文(简体)
2. 在亚克斯行动+阿斯普.net MVC 3 中找到路线价值
原标题:Get route values in ajax action + Asp.net MVC 3

In Post Controller , URL is like this :

     http://127.0.0.1/post/5006/some-text-for-seo-friendly
     {contoller}/{id}/{seo}

     public ViewResult Index(){
     .....
     }

I used Ajax.BeginForm in index view and mapped it to AddComment action in the same controller.

  @using (Ajax.BeginForm("AddComment", "Post", new AjaxOptions()
                   {
                      HttpMethod = "GET",
                      InsertionMode = InsertionMode.InsertAfter,
                      UpdateTargetId = "comment-container"
           }))
            {
                <textarea cols="2" rows="2" name="comment" id="comment"></textarea>
                <input type="submit" value="Add Comment" />
            }

and in controller

    public PartialViewResult AddComment(string comment){
              // how can I get 5006 {id} here
    }

my question is how can I get the {id} [5006] in AddComment action.

注:难以使用<代码>查询。 UrlReferer, 并按/和选定表格阵列分别列出。

最佳回答

You need to supply the id to the BeginForm method using this overload which takes a routeValues parameter:

@using ( Ajax.BeginForm( "AddComment", "Post",
  new { id = 5006 },
  new AjaxOptions
  {
    ...

那么,你就应当能够把id作为你的行动方法的参数:

public PartialViewResult AddComment( int id, string comment )
{
  ...

MVC将使用AddComment,其人口价值为:

问题回答

暂无回答




相关问题
Rails: Proxy Pass?

I ve got a web-app that I want to migrate to Rails, which is currently just plain HTML with an Apache proxy to another server, running a custom database/webserver that serves the site s dynamic ...

MVC routing is not handling one of my directories

I m using ASP.NET MVC with IIS 7.0. I ve got 404 errors hooked up fine through my Application_Error override. In addition to "Controllers", "Models", "Helpers" etc. I have a directory called Files ...

Ruby on Rails conditional routing

I have a site listing many jobs, but I also want each account to be able to access its jobs in one place. Thus, I am using these routes: map.resources :jobs map.resource :account, :has_many => :...

Clean URL s using OpenCart s router class

How do you write clean URL s in OpenCart using their built in Router class? Here is my .htaccess file: RewriteEngine On RewriteRule ^(system) - [F,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{...

subdomain routing to multiple controller issue

I have a site: www.mydomain.com where we have administrative controls hidden away from normal customer view. I would like to only access the administrative features under a subdomain such as admin....

Can controller names in RESTful routes be optional?

With a standard map.resource routing mechanics and several nested resources the resultant routes are unnecessarily long. Consider the following route: site.org/users/pavelshved/blogs/blogging-horror/...

Help with rails routes

Im having a little trouble setting up routes. I have a users controller/model/views set up restfully so users is set up to be a resource in my routes. I want to change that to be usuarios ...

热门标签