I need to add an attribute to the form tag (Html.BeginForm) and the value of this attribute must be the parameter of the edit action (ID).
How can I do this?
Here is my action code:
//
// GET: /Panel/Partners/Edit/5
public ActionResult Edit(int id)
{
var repository = new PartnersRepository();
var data = repository.Find(id);
return View(data);
}
And here is the code for the form tag:
@using (Html.BeginForm("Edit", "Partners",
FormMethod.Post,
new {
enctype = "multipart/form-data",
id = "partnersForm",
data_removelogo = @Url.Action("RemoveLogo", "Partners", new { Area = "Panel", id = Model.ID }) }
))
The Url.Action from the data_removelogo attribute doesn’t work with the Model.ID property.
From your comments it sounds like you are passing a
nullmodel into your view. When you try and access any properties on a null reference you’re going to get the error you’re getting. You either need to make sure in your controller that you don’t pass in a null model, or in your view you’re going to need logic to handle a null model, such as checking for null before accessing the id.