How To Send Along Non-Model Data From Html.BeginForm?

Umbracians,

I am building a site in Umbraco 7, using MVC4. I have a working form from which I can successfully post data back to the controller.

However, I would like to include two radio buttons on the form that are not bound to the model.

The radio buttons will let the user pick whether their last name is equal to their birth name. If true, then I want to send this along to the controller, so that I can assign the LastName property to the BirthName property.

In my controller, I have the following code:

public RedirectResult Submit(User user, Dictionary<string, object> htmlAttributes)
{
	// some code...
	return Redirect(this.Request.UrlReferrer.ToString());
}

In my razor view, I have the following code:

@using (Html.BeginForm("Submit", "MemberAddressForm", FormMethod.Post, new { Name = "Jay" }))
{
    // strongly typed, working form declaration

    // two non-model radio buttons
<label for="rbLastNameEqualsBirthNameTrue">Yes</label>
<input type="radio" id="rbLastNameEqualsBirthNameTrue" name="lastNameEqualsBirthName" value="true" checked="checked" />
<label for="rbLastNameEqualsBirthNameFalse">No</label>
<input type="radio" id="rbLastNameEqualsBirthNameFalse" name="lastNameEqualsBirthName" value="false" />

}

My first problem is that I am not getting key/value pair {Name=“Jay”} in my controller htmlAttributes parameter. It does hold two parameters, but those are for the controller name and the controller action. Why is my own custom key/value pair not being added? Am I not accessing my html attributes in the right way?

My second problem is that I need to figure out how to send along the non-model radiobuttons’ value, rather than my own hard coded name. How can I do this?

Is what I’m trying to do even possible? If so, is this also the best practice? If not, then how should I do it? Should I modify the model?


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/60091-how-to-send-along-non-model-data-from-htmlbeginform