Reputation: 1823
I'm using:
I've got a table Role:
(One column that's called RoleName, datatype varchar(50) and is the primary key)
When I create a strongly-typed view with as model class Roles (extra 's' is caused by pluralisation, no issue) and scaffold template Edit, the result is that I only get a hidden field and no edit/input field, as shown below:
<fieldset>
<legend>Role</legend>
@Html.HiddenFor(model => model.RoleName)
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
This is likely due to the only column being the primary key which MVC uses to identify the database record.
I want to be able to edit every Role's RoleName. How can I make an edit page for a table with one column that is the primary key?
Upvotes: 0
Views: 753
Reputation: 39807
Just adjust the scaffolded HTML markup to fit what you need. You are correct that MVC made that hidden because it is a primary key. Unhide it.
<fieldset>
<legend>Role</legend>
@Html.TextBoxFor(model => model.RoleName)
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
However, and this may just be subjective, I think having an int based primary key will go a long ways in doing things like:
Upvotes: 2