Adding multiple dropdown on clicking a link - asp.net-mvc

I have a link which says "add another field". On clicking the link a dropdown should appear on top with let's say 5 custom fields as list in dropdown. Once user selects a field in that dropdown and clicks hyperlink another dropdown should appear below existing dropdown and with only 4 remaining fields as one is already selected.so how to start this?
https://tutorialslink.com/Articles/How-to-add-control-dynamically-in-Aspnet-MVC-using-Javascript/64 . I have tried to use this link which adds text boxes to get started.
I don't have any code expect for the code in above link which is for text box though. Just need an idea of how to do it in asp.net MvC as i cannot move forward now.
Expected results is to do the above requirement, don't have any actual results as of now

Related

Rails form select from two options with a button - custom form implementation

I have a website where I want users to be able to select what type of user they are during the registration process.
Specifically, the implementation I want is to have two buttons on the signup page, one called "Seller" and one called "Buyer".
The user should be able to select only one button and once clicked, it should stay highlighted (I know this is just jquery so not the issue).
The selection should be stored in a column in my users model called :type.
It seems pretty straightforward, but the "f.select" form method seems to only implement a dropdown menu, so I am wondering how I can achieve this implementation of two buttons.
Since you're already going to use jQuery, you could add a hidden field for type, create 2 links and style them as buttons, and use jQuery to update the value of type when a user clicks one of the "buttons".

List box values on postback

I am using asp.net mvc. I have used two list box in one of my views.
I transfer desired items from left-hand-side list box to right-side list box.
On a button click, i want to get the list box contents from right side list box.
I don;t get in form collection. Can anyone please suggest how can I get it?
thanks,
kapil
The only values in the list box that are selected will appear in the form collection.
When you transfer to the second list box, I would add a hidden field and add the cvalues into there (with some delimiter between). Upon POST you could split the string value of this hidden value to find contents of right hand list box.
Alternatively, just prior to Submit (intercept with JavaScript), set all values in right hand list box to selected.

ASP.Net MVC - which is the best approach for multi select grouping using JQuery Dialog

This is my scenario
I have an view(page) with list of items, a user could select single or multiple items from this page and click on a "Add to Group" button. Then a modal dialog(JQuery dialog) will be shown, from that he could select group, then press the add button. Which causes the items selected in the parent page is added to that particular group.
So, which is the best way to pass the selected items to the modal pop-up?
Though the query string ? - what happens if the no:of items selected is large, will the url support that much characters
Keep the list in the parent page in a javascript variable and return the selected group from the modal pop-up?
Or is there is any other better option?
Thanks,
Rajeesh
2a. There is no "parent" page; modal dialog is part of the same page as selected items. Therefore on "OK" function from the dialog you can go through the checked items and do whatever you want, including POSTing to the server. It's not clear from your post whether "adding items to the group" happens on the server or client

How to know which radio button is selected on a view?

I have a created a list view for one of my controller's index action.
I have added a new column "Select This" to this list view, by using the view's source.
The column will contain radio button for each entry in the list. This i have achieved by just placing a radio button control from tool box in the "Select This" column. This i have done in the design of the view and when i run it, i get radio buttons, one for each of the entry. The page also has a link button and i want to call a controller action on this link button click which will receive the index of radio button selected. So if i select 5th radio button, how can receive 5 in the controller action.
How can i do this?
Regards,
kapil
If you used plain HTML, your radio buttons will all have the same name, but different value. You will get one result in the POST, which will contain the selected value.
If you used ASP.net helpers, it's the same, but they will be generated for you: see here: http://msdn.microsoft.com/en-us/library/dd410596.aspx You will pass the same name (first parameter) and different values for each input (second parameter).

ModelState.IsValid for invisible controls

I am working on MVC with C#.
I have 2 radio buttons. On selecting first radio button, a textbox will be shown which allows to enter date values.
<%= Html.TextBox("ReceivedDate")%>
on selecting the second radio button, the textbox gets hidden.
For the first time, when i select first radio button and entered date and clicked Next to navigate to next page and came back to this page again and clicked second radio button and clicked Next to continue and again i came back to this page and without changing any option click continue, its not allowing to navigate and shows an error.
A value is required.
Which means the ModelState validating the hidden controls also.
Please suggest how to control it
Instead of hiding it remove the element from the DOM and reinsert it if the first item is selected again. Another way would be to change the name of the input control to something else (a key not present in your model data) when the first item is not selected.
Validating hidden input types is a good thing, i often use them to synchronize data from complex controls (like a treeview with checkboxes). An input type with a hidden css style doesn't make it not submit with the form it belongs too.

Resources