Reputation: 1403
In my MVC project I have three links on the "Index" page which all launch the same "Create" view. I would like to pass a flag to the view that allows me to determine which of the links was used to launch the view.
I have achieved this by creating a new instance of my class, setting the "mode" property and passing the model to the view.
For example, in the "Index" view I have:
@Html.ActionLink("My Link 1", "Create", New With {.id = 1}, Nothing)
@Html.ActionLink("My Link 2", "Create", New With {.id = 2}, Nothing)
@Html.ActionLink("My Link 3", "Create", New With {.id = 3}, Nothing)
The "Create" in my controller would be:
Function Create(id As Integer) As ActionResult
Dim myObject As myObject = New myObject
myObject.Mode = id
Return View(myObject)
End Function
This only seems to work if I have an editor in my view that references the "Mode" property. If I leave the following code in my view everything works fine however if remove it (because I do not want to display it on the form) the "Mode" property is always set to 0.
<div class="editor-label">
@Html.LabelFor(Function(model) model.Mode)
</div>
<div class="editor-field">
@Html.EditorFor(Function(model) model.Mode)
@Html.ValidationMessageFor(Function(model) model.Mode)
</div>
How can I set the "Mode" without displaying it in my view?
Upvotes: 2
Views: 109