MVC3: button to send both form (model) values and an extra parameter

asp.net-mvc-3, button, parameters

Solution

My advice would be to declare a new Object in your App.Domain.Model something like this

namespace App.Domain.Model
{
    public class CustomEntity
    {
        public Project projectEntity { get; set; }
        public int variableUsed { get; set; }
    }
}

In your view you can acces them easily by using CustomEntity.projectEntity and CustomEntity.variableUsed.

Hope it helps

Problem

In an MVC3 project, i use an Html.BeginForm to post some (model-)values. Along with those i want to send an extra parameter that is not part of the form (the model) but in the ViewBag. Now, when i use a Button (code in answer here: MVC3 razor Error in creating HtmlButtonExtension), all the form values are posted but the extra parameter remains null. When i use an ActionLink, the parameter is posted but the form values are not :) Any know how i can combine the two? Thanks! ``` @Html.Button("Generate!", new { id = ViewBag.ProjectID }) @Html.ActionLink("Generate!", "Post", new { id = @ViewBag.ProjectID }) ```

Original source