Controller
First I tried this:
[HttpPost]
public ActionResult Edit(JournalEntry journalentry)
{
if (ModelState.IsValid)
{
Actually you could rename the JournalEntryId
property in your JournalEntry
view model to Id
and then the default model binder will automatically populate it for you so that you don't have to write the following line:
journalentry.JournalEntryId = id;
and your first code snippet will work because the Id property will be populated with the value from the route.
Or if for some reason you cannot rename the property on your view model (actually I know the reason => you are not using any view models at all but you are passing your domain entities directly to the view which is bad but subject to another question), you could use a hidden field in your form:
@Html.HiddenFor(model => model.JournalEntryId)
or modify your Html.BeginForm
declaration to include the parameter as query string argument:
@Html.BeginForm("Edit", "SomeController", new { JournalEntryId = Model.JournalEntryId }, FormMethod.Post)
{
...
}