Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 818855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:12:54+00:00 2026-05-15T02:12:54+00:00

I am trying to call Action method passing a single parameter. The method (Accepts

  • 0

I am trying to call Action method passing a single parameter.

The method (Accepts Http Posts) is being hit when the submit button is clicked (following a dialog popped via java script for the user to confrim). However the value passed into the action method is alway null. Below is a snippet of the Page source rendered to the browser. This shows two typical rows. There are no other ‘Form’ elements on the page.

Any ideas as to why the value is not passed.

Thanks

Grant

<tr class="inactive-row">
    <td>Title1</td>
    <td></td>
    <td>01 January 2010</td>
    <td>
        <form action="/Admin/Delete/1" method="post" onsubmit="return confirmDelete()">
            <input type='image' src='/Content/delete.gif' value='delSubmit' alt='Delete' />         
    </td>
</tr>

<tr class="inactive-row">
    <td>Title2</td>
    <td></td>
    <td>01 January 0001</td>
    <td>
        <form action="/Admin/Delete/2" method="post" onsubmit="return confirmDelete()">
            <input type='image' src='/Content/delete.gif' value='delSubmit' alt='Delete' />         
    </td>
</tr>

Thanks for you help. Below is the global.asax code:

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
             new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
    }

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);
    }
}

AdminController:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Xml.Linq;
using System.Xml.XPath;
using DataGridInMVC.Models;

namespace DataGridInMVC.Controllers
{
    public class AdminController : Controller
    {
        private XDocument document;
        //
        // GET: /Admin/

        public ActionResult Index(int ? PageNumber)
        {
            var data = GetPostData(PageNumber);
            //Build the model and then Sent to the View
            return View(data);
        }

        private MyAdminDataModel GetPostData(int? pageNumber)
        {
            document = XDocument.Load(Server.MapPath("~/App_Data/Posts.xml"));
            var elList = from el in document.Descendants("Post")
                         select new Page { ID = (string)el.Attribute("ID"), PermaLink=(string)el.Attribute("PermaLink"), Title = (string)el.Attribute("Title") };

           return new MyAdminDataModel { CurrentPage = pageNumber ?? 0, Pages = elList, TotalPages = 2 };
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Delete(int ? delId)
        {
            document.XPathSelectElement(String.Format("Posts/Post[@ID = '{0}']",delId )).Remove();
            document.Save(Server.MapPath("~/App_Data/Posts.xml"));
            var model = GetPostData(null);
            return View("Index",model);
        }
    }
}

The Extension methods for htmlHelper:

public static string DeleteForm(this HtmlHelper helper, string controller, string action, int id)
{
    //UrlHelper url = new UrlHelper(helper.ViewContext);
    UrlHelper url = new UrlHelper(helper.ViewContext.RequestContext);
    string postAction = url.Action(action, controller, new { id = id });

    string formFormat = "<form action=\"{0}\" method=\"post\" onsubmit=\"return confirmDelete()\"/>";
    return string.Format(formFormat, postAction);
}


public static string SubmitImage(this HtmlHelper helper, string imageName, string imageFile, string altText)
{  
    return string.Format("<input type='image' src='{0}' value='{1}' alt='{2}' />", imageFile, imageName, altText);
}

The code I have is from Rob Conery’s Blog
http://blog.wekeroad.com/blog/asp-net-mvc-avoiding-tag-soup/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:12:55+00:00Added an answer on May 15, 2026 at 2:12 am

    In the above code I think you’re missing closing tags for your form tags.

    EDIT: Any reason you don’t want to use Html.ActionLink instead of a submit button since it looks like you don’t need any form data submitted and an ActionLink is nice a light?

    EDIT 2: Try changing your controller Delete method definition to:

    public ActionResult Delete(int? id) 
    

    I think it can’t match up the params properly. I just tested your code and the param name is definately the problem. I was able to reproduce the same issue but renaming it to id solved it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to build call to action button on my site using jQuery. I
I'm trying to call a method from another class with a simple button in
I'm trying to call an action method in an MVC application using jQuery. Basically
I am trying to achieve a JQuery AJAX call to a controller action method
I'm trying to make a post call to an action method in MVC 2.
Im trying to call a method that will add or subtract 1 from a
I trying to call 2 functions in the same page to submit jquery-ajax at
I am trying to call the browse() method of the FileReference class from JavaScript
I am trying to call an ASP.NET MVC actionMethod via the JQuery ajax method.
I'm trying to do this: def assert_record_not_found(method, object, action, params) begin method action, params

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.