This is probably another dumb question....
I'm new to ASP.NET MVC and I'm following The NerdDinn开发者_如何学Cer 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:
public ActionResult Create() {
ViewData["ButtonText"] = "Create";
...
}
And in the partial view:
<p> <input type="submit" value="<%= ViewData["ButtonText"] %>" /> </p>
Disclaimer: This code is untested and might contain errors
You could use JavaScript to do it. Load the edit value when the file is loaded and then set the value of the button.
精彩评论