J'essaie d'appeler la méthode Action en transmettant un seul paramètre.Paramètres ASP.MVC non transmis à la méthode Action pour le poste http
La méthode (Accepts Http Posts) est en cours d'exécution lorsque vous cliquez sur le bouton Soumettre (suite à une boîte de dialogue sautée via un script Java pour que l'utilisateur se contente de confirmer). Cependant, la valeur passée dans la méthode d'action est toujours nulle. Voici un extrait de la source de page rendue au navigateur. Cela montre deux lignes typiques. Il n'y a pas d'autres éléments 'Form' sur la page.
Aucune idée de la raison pour laquelle la valeur n'a pas été transmise.
Merci
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>
Merci pour votre aide. Ci-dessous le code global.asax:
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);
}
}
}
Les méthodes d'extension pour 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);
}
Le code est à moi est le blog de Rob Conery http://blog.wekeroad.com/blog/asp-net-mvc-avoiding-tag-soup/
Informations insuffisantes. Postez ici vos méthodes d'action global.asax et controller. –
Merci pour votre aide. J'ai maintenant inclus le code galbal.asax –
Pouvez-vous poster votre contrôleur s'il vous plaît? –