This is probably another dumb question….
I’m new to ASP.NET MVC and I’m following The NerdDinner tutorial online. I’ve reached the section regarding partial views which shows how to reuse a ascx form to create or edit a row for the database. The ascx form has a submit button:
<p>
<input type="submit" value="Create" />
</p>
For the create.aspx form, the value has to be ‘Create’ but for the edit.aspx form the value has to be ‘Save’. How do I change the value of the button?
I know I could just place a seperate button on each of the forms, but since they both need a button in the same place, I thought there might be a better way.
Thanks
Just change the “value” attribute to whatever you want the button to say. There is no rule that says it has to be Create for the Create action.
Edit
I think I totally misunderstood the question, it’s your rule that the button has to say Create in the Create action right?
You could do this by adding a value to ViewData in the controller.
Something like this in the controller:
And in the partial view:
Disclaimer:
This code is untested and might contain errors