0

I am a bit new to mvc razor and building websites (front and backend). The break down is, I need a button that has a value stored in it be sent to the controller/model. Something similar to html boxtextfor. I have tried giving boxtextfor attributes similar to an input submit button, but it doesn't like that. I have tested the button using javascript and it does have the value within each individual button (# of buttons are dynamic based on previous submit).

I have seen posts like this but I am unsure how to add these to my controller or model so my index page can call it. My model is linked to my index page so I guess I could link these methods in my model.

There's no @Html.Button !

(tried this, but it needs to be linked to my model. A simple button doesn't work.) Looking for a Html.SubmitButton helper that would accept class attributes in MVC3

I currently don't have access to my code in question. The button needs to be an input submit to go to [HTTPPOST]. However, if you need any more information please let me know.

Thank you for your time,

HtmlNooby

  • `` or `@Html.HiddenFor(m=>m.submitValue)` - is there a reason it needs to be on the button? Do you have multiple buttons? – freedomn-m Feb 02 '20 at 22:21
  • Yeah, I am updating an old system that is PHP and the previous page and users are used to the buttons. So, I am recreating the page using MVC razor to be compatible with the new website. Thanks for the suggestion! I will work on it tomorrow. – user12387441 Feb 02 '20 at 23:29
  • If you have multiple buttons, you can determine which butt caused the submit without a hidden field, using this: https://stackoverflow.com/a/7111222/2181514 - no doubt it can be extended to add additional information to a single button, so not reliant on multiple buttons. – freedomn-m Feb 02 '20 at 23:37

1 Answers1

0

I solved it by wrapping a button with the following. This creates binds each individual button with the given item from an array. Kind of acts like a buttonfor if you will.

Foreach item in array{
  @using(Html.BeginForm(…)
  {
    <button class=input value=item>item</button>
  }
}