I'm currently building a web application using ASP.NET MVC. I have a few forms in my view that receive data to be put into a post response body. I would like to attach those inputs to my view model, and then pass my view model back to my controller in order to work on them.
Here's a sample of something I have in my web app:
<select id="ServiceSelect" size="3" style="width:600px; overflow-y:auto" multiple="multiple">
<option value="Service 1" class="pad">Service 1 </option>
<option value="Service 2" class="pad">Service 2</option>
<option value="Service 3" class="pad">Service 3</option>
</select>
<input type="hidden" id="service" name="service" value="" />
<!-- this puts the two buttons side by side after the select -->
<br />
<input type="submit" name="start" value="Start Service(s)" />
<input type="submit" name="stop" value="Stop Service(s)" />
(the hidden input is populated using jQuery functions based on select form)
I would like to make use of Razor Pages' model binding characteristics in order to add my hidden input to my model upon selecting one of the submit buttons. Currently, through Fiddler, I can see that it is populating the response body correctly, but I'm thinking the native MVC model binding might be a cleaner approach.
However, in code examples like such:
<td>
@Html.DropDownListFor(m => m.Gender /* <- this being what I want */, new List<SelectListItem>
{ new SelectListItem{Text="Male", Value="M"},
new SelectListItem{Text="Female", Value="F"}}, "Please select")
</td>
I can't see a way to include my current functionality and style that I have set up with my own select tag (multiple select, style).
I'm new to Razor Pages, so I don't quite know the syntax well for it's built in functions. I find the raw HTML to be easier to code, read, and style, but haven't been able to find any online resources in order to help me with this problem.
Is there a way to take advantage of MVC/Razor Pages model binding characteristics while incorporating one's own HTML forms, rather than the less extensible (to my possibly misguided knowledge and opinion) built-in @Html ones?