I have an ASP.NET Core project that my user will insert a first personal ID that will make my view bring several of information about this person.
But there's a condition where my user maybe needs a second personal ID to be show. If this happen, my user will mark a field, where he will insert the Second Personal ID. After that my view needs to show several information about this person like the first one (is bascicly a copy of all fields that i search for the first personal id)
The question is, how can I achieve this? This view is like a presentation for the user, just recovering all fields that I already have in database and with a field in the final of the page, the user can Edit what is missing, but because that condition for second a Personal Id need to be inserted, how can i make work? Did I need another instance of my view object (now with the second Personal ID) to get this information, and how will I trigger this when I am already inside the view?
Both IDs exists in the database, so will be a second query
Here is where this condition can be applied, all fields
<div class="col-12">
<div class="col-12">
<select id="GarantiaSelection">
<option value="selecione">selecione</option>
<option value="Sim">Garantia Real</option>
<option value="Não">Garantia Pessoal</option>
</select>
</div>
</div>
Then, if the condition is "Não" the second Personal ID is needed:
<div>
<label>Digite o CPF do Garantidor</label>
< type="text"> </>
</div>
After that, it will show fields about this person, like
<div class="col-3">
<label for="Renda Liquida">Relacionamento</label>
<input type="text" class="form-control">
</div>
<div class="col-3">
<label for="Renda Liquida">Atualizaçao Cadastral</label>
<input type="text" class="form-control">
</div>
</div>
If you select option 2 for example, I want to send both the value 2 (for the amount of books to be added) but also the Book_ID for the chosen book.
So in my method that retrieves the form I expect to get both an integer value of 2 and also an integer value for my Book_ID.
I was hoping you could do something like
<option value=#ShoppingCartItem.Book_ID value="1" >1</option>
but that obviously didn't seem to work.
Below is a code snippet from my current View.
#foreach (Lab2.Models.ShoppingCartDetail ShoppingCartItem in Model.ShoppingcartList)
{
<tr>
<td>#ShoppingCartItem.Title</td>
<td>#ShoppingCartItem.Author</td>
<td>#ShoppingCartItem.Price :-</td>
<td>#ShoppingCartItem.NumberOfBooks</td>
<td>
<form action="UpdateNumberOfBooks" method="POST">
<div class="form-group">
<select class="form-control" id="NumberOfBooks" name="NumberOfBooks" onchange="this.form.submit()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</form>
</td>
</tr>
}
If it's possible, how should my method look that retrieves this information?
Just add that value as an <input> to your form. For example:
<input type="hidden" name="Book_ID" value="#ShoppingCartItem.Book_ID" />
This would include the Book_ID as a separate value in the same <form>.
how should my method look that retrieves this information?
Presumably you have a method which receives something like this, no?:
public IActionResult UpdateNumberOfBooks(int numberOfBooks)
If that's the case, you'd just include this second value as well:
public IActionResult UpdateNumberOfBooks(int book_ID, int numberOfBooks)
Or if NumberOfBooks is included as part of a model, you'd add Book_ID to that model. Basically, however you currently receive the one value you have now, you'd add the new value alongside it.
I have a drop-down list like
<div class="form-group">
<label>
<span>Status:</span>
<select name="status" id="status">
<option value = ''>Please select</option>
<option value="Passed">Cleared</option>
<option value="Failed">Redo</option>
<option value="Improvent" value ="second level improvement" value="third level improvement">Pending</option>
</select>
</label>
</div>
I am fetching data from SQL using asp.net webmethod. How can I have multiple values inside option tag? In my database, if I have either improvement or second level improvement or third level improvement I should display as pending. In database value, if the value is passed I was able to display cleared and if the value is failed I was able to display Redo. I am not sure how to have multiple values in option tag. If it can be done on the server side can anyone explain how can i do with asp.net?
i am creating a web app and i have a dropdownlist
<select id="drdsearch" ng-model="drd" style="margin-top:-39px; margin-left:300px; height:30px; width:200px; font-size:12px;"><option value="select">select</option>
<option value="default">Default</option>
<option value="venue">Venue Name</option>
<option value="date">Date</option>
</select>
with these textboxes
<input type="text" ng-hide="true" ng-show="drd=='default'" placeholder="d" name="default">
<input type="text" ng-hide="true" ng-show="drd=='venue'" placeholder="e" name="venue name">
<input type="text" ng-hide="true" ng-show="drd=='date'" placeholder="l" name="Date">
i used angularjs for (hide/show)textboxes but now when i run my program dropdown automatically included an extra blank option field
now there are four fields in my dropdow
1st ( )blank
2nd default
3rdvenue
4thDate
what i need to do to remove the extra (blank option) from the dropdownlist
Initialize the value in your $scope.drd with 'default' and you should be fine.
I have the following:
<form name="input" method="get" action="http://site:8083/Default.aspx?DC=" target="foo" onSubmit="window.open('', 'foo', 'width=1100 height=500,status=no,resizable=yes,scrollbars=yes')">
<select name="DC">
<option value="1&Type=type1">1</option>
<option value="2&Type=type2">2</option>
<option value="3&Type=type3">3</option>
<option value="4&Type=type4">4</option>
<option value="5&Type=type5">5</option>
<option value="6&Type=type6">6</option>
<option value="7&Type=type7">7</option>
</select>
<input type="submit" value=">>"/>
</form>
Basically my querystring should be something like DC=1&Type=type1 the problem I have is that when I click the >> button above the html screws up the stirng by changing & to %26 and = to %3D
How can I make the value stay as I have it in the code above?
Yes, that's the expected behaviour, the HTTP GET works this way, values are encoded to difference from keys. In GET, browsers append key=value pairs separated by '&' and starting with a '?'; you shouldn't specify them by yourself in the url.
I think you should change your code in this way, maybe it's what you want to get:
<form name="input" method="get" action="http://site:8083/Default.aspx" target="foo" onSubmit="updateType()">
<select name="DC">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<!-- etc... -->
</select>
<input type="hidden" name="Type"/>
<input type="submit" value=">>"/>
</form>
and in Javascript...:
function updateType(){
// set up 'Type'
document.forms[0].Type.value = 'Type' + document.forms[0].DC.value;
// open popup
window.open('', 'foo', 'width=1100 height=500,status=no,resizable=yes,scrollbars=yes')
return true;
}
Forms are designed to submit key/value pairs of data where the key is the name of the control and the value is the value. They will not mash arbitrary strings together.
Design your server side program to expect input in the format the forms are designed to use.
...and this is correct. Request-Parameters [get] should be encoded.
When you get the Request, your Server should decode them [apache/php] or i don't know ASP but in php it gaves a function called urldecode() ...
Try using:
HttpUtility.UrlDecode()
Further reading
So what you're trying to do is have two different query string set to two different values when a single item on your form is set. While your attempted solution is a neat idea, clearly the browser is actively preventing you from using that method (for security reasons) and rightly so. I see two solutions that would work well for you.
Use the form to send just one query string (i.e. DC) and on the server side, determine what the value of 'Type' should be. If it's really, really important to have both values as query strings (for example you're re-using a Control that only looks at those query strings) then use Server.Transfer on the server side to add the additional query string(s).
Provide two types of inputs on the form. One being the select box that you have there, another being either a hidden select box, a hidden input field, or whatever else fits for you. Add Javascript to the page such that when the selection is changed on the visible select box you set the hidden field to the correct value, then when the form is submitted both inputs are each submitting only one query string, as the browser is designed to support.
Here's an implemention of choice #2:
<script type="text/javascript">
var DCMapping = new Array();
DCMapping["1"] = "type1";
DCMapping["2"] = "type2";
DCMapping["3"] = "type3";
DCMapping["4"] = "type4";
DCMapping["5"] = "type5";
DCMapping["6"] = "type6";
DCMapping["7"] = "type7";
function selectionChanged(selectBox)
{
alert(DCMapping[selectBox.value]);
document.getElementById('hidType').value = DCMapping[selectBox.value];
}
</script>
<form name="input" method="get" action="http://site:8083/Default.aspx" target="foo"
onSubmit="window.open('', 'foo', 'width=1100 height=500,status=no,resizable=yes,scrollbars=yes')">
<select name="DC" onchange="selectionChanged(this)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
<input type="hidden" name="Type" id="hidType" value="1" />
<input type="submit" value=">>"/>
</form>
You should use:
HttpUtility.UrlDecode();
To convert escape characters in the url
You can remove the method and action from the <form>. Instead extend the JavaScript/VBScript to pick up the value of the selected option and catenate it with the url root.
You don't need to mess with url decoding, the %.. should work fine as-is.