Disable form fields and enable them after clicking on edit button - asp.net-mvc

I have a form fields in which I am displaying data.
The values should be disabled and edit button should appear, after clicking on Edit button, the values should be enabled and user can edit the data and only save button should appear
How to achieve these two requirements in a single form in Asp.Net MVC4?

Use templates.
An ITEM TEMPLATE and then an EDIT TEMPLATE.
When the user presses the EDIT button, set the action to change to mode of the form to EDIT.

Related

Adding multiple dropdown on clicking a link

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

JSF2 render retraining old values

I am using JSF2 with #ViewScoped
I have table listing, cliking on row opens record in disabled='true mode'
2- ON the popup in disabled view button called 'Edit'
3- When user clicks upon edit button, all fields on the form which are disabled will become enabled.
Problem is in disabled mode it is fine but when user clicks upon edit button it start displaying few values from old record which was being clicked.
It is not happening every time but randomly when you start clicking.
I am not reloading any data when user clicks upon edit button instead I only make ajax call and set attrib val to true and on the bases of that I render model values and it dispalys enabled values.
is it cache problem or any thing else ???
help required.
In your bean set enableStatus =0;
and in edit button and all of your text fields, set disabled="#{bean.enableStatus==0}"
when u will click on edit then set enableStatus = 1 in your action method and reRender it.
You will get what you want....

Browse button not in form

How to implement a browse button which would not be in a form tag in MVC?
I want a normal button - when clicked, to handle the file selected.
This is impossible to do. The browse button has to be in a form tag.

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.

MVC question - hide /show a panel with partial postback from radiobutton submit

I have 2 radio button with values New & Existing. If user chooses New, then I show a textbox on the form and if Existing a dropdown and textbox is hidden. The question is , does the hide/show of the textbox/dropdownlist have to be written in the View or the Controller class? Also when I choose the selection my whole form is posting back and hence all validation error msgs are being shown which should not be shown nless the save button is clicked, how do I a partial postback without full form submission? Any code snippets or urls would be benificial in this respect.
The question is , does the hide/show of the textbox/dropdownlist have to be written in the View or the Controller class?
Just show/hide with jQuery that.
Also when I choose the selection my whole form is posting back and hence all validation error msgs are being shown which should not be shown nless the save button is clicked, how do I a partial postback without full form submission? Any code snippets or urls would be benificial in this respect.
Perform 'partial postbacks' through javascript.
Post form to save action only once when it's ready (when Save button is clicked).
Some resources:
jQuery tutorial
jQuery AJAX
About form AJAX`ifying
If I understand you correctly, the answer is the hiding and showing of controls should be done on the view as it's display specific.
If you use javascript to show and hide the controls then because it's on the client side you would not have to postback the form, and could do server side validation when the save button is clicked.
jQuery is very good: Jquery Website
Hope that helps?

Resources