Pass input id value in MVC from view
How can I pass the value of an input field from a view to a URL as an ID and not a GET parameter?
My home controller returns an extra view if the query string is empty.
local: 1111 / home / work / 1
will return a list of results from a table based on id, whereas:
local: 1111 / home / work
will return the view "Empty".
An empty view contains a very simple form that is functional and returns the table results, however I need the url to be in the correct format {controller} / {action} / {id} where the id is from the input, If currently I get {controller} / {action} /? Jobno = 1
Empty view:
<form action='home/job/' method="post">
<input type="text" name="jobno"/>
<input type="submit" value="Submit" />
</form>
+3
source to share
1 answer
Can you try the following:
<form id="form1" action='/home/job/' method="post">
<input id="jobno" type="text" name="jobno"/>
<input type="submit" value="Submit" onclick="AddingQS();">/>
</form>
<script type="text/javascript">
function AddingQS(){
var formaction=document.getElementById('form1');
formaction.action+=document.getElementById('jobno').value;
}
</script>
Here is a working fiddle
+1
source to share