I have page that has 2 forms posting back to the same controller
The first form posts back and the result sends back an updated model to allow the second form to appear on the page.
Concept is the user is shown items from a list they want to select to return.
HTML for this is as follows:
The page sends that form back to this controller
With this model
The 'GetModel' is the model that is past back to the page
Then sends back to the same page to allow a preview of what they want to return for the user to confirm.
When the second form as below:
is posted back the the same controller and function again model is completely empty but cant see why?
Related
I have a razor view with the path ~/Views/ReservationDetails/AddMeals.cshtml which is rendered by the controller ReservationDetails. In the View I use the following Html helper action link:
#Html.ActionLink("Wróć", (ViewBag.ReservationId!=0?"Edit":"Create"),"ClientReservations",new { id=ViewBag.ReservationId})
When I edit MealsReservations and I want to come back to Edit it redirects me to ReservationDetails/Edit/Length=18?
However when I add meals for reservation for the first time and I want to come back, then it redirects me properly to Create in controller ClientReservations.
What can it be the reason?
The scenario is - There are two view in my mvc application. One is Index and other is for adding payment details. in index form I fetch details of a perticular client in that I have cascading dropdown one for selecting type and one for according to type select client in another dropdown, both are coming from DB's and on d same view I have an ActionLink for going on Payments view "for adding the payment details for the same client that is been selected on Index views second dropdown (first is for Type)".
My problem is that when I am going on Payments view and clicking back button of browser to go back on my index page it is clearing the second dropdown. and all other data is safe on the form. So can you please help me to avoid this so that all the data of my Index view should retain throughout the execution.
This also in case when I add Payment for that client and click submit it should redirect on the Index view with retaining all its previous data. that we have fetched on Index page.
with a message box Payment Added successfully.
You can save the current selected values of dropdown1 and dropdown2 into one of the followings:
URL
Session
Cookie
Then in the Index page you always check to read those values if they are existed to setup the dropdowns in the first request. Then do update those values again whenever user selects to update the dropdowns.
I have a form which has two buttons
One will assign the form, i mean create an entry in corresponding table after validation and redirect to another page
Second will give a preview of the values submitted on the form.For the preview screen we need some calculations so that an action to be called from controller and respective page will be loaded.
This page should seen on the same form if i clicked preview before assigning the form
How i would address this is to change your new action so that it takes the same params as the create action, and makes the object but doesn't save them. This means that if you call the new action with the params it will reload the form with the built but not saved objects' data displayed in it.
The two buttons will need to change the form's action attribute so that it submits to the create or the new action as appropriate.
This is a general answer, as your question is quite general!
I have a requirement to include logon fields in my right column of a 3 column layout, with the body view being the centre. Right now I simply have Logon actions in my home controller, but IN haven't given this much work yet and am running into difficulties. I use a partial view for the HTML form with login fields, but I want to move the logon actions into my Account controller. However, my quandary is how to. so to say, return a partial view from an action method, e.g. for a bad logon message.
For that purpose, Html.RenderAction is used. Simple way to inject output of other menu, logon, etc. actions into generated html
Do you use AJAX or you submit the form back?
I would suggest using AJAX to send the form data. If the login is unsuccessful you can return some string or whatever message you like (you can also return the partial view), if it is successful you can authenticate the user and redirect to home page.
Wasnt sure how to word the question, but this is the scenario:
the view is a data entry form eg http://127.0.0.1/User/AddEdit/
so edit the user I have an ID: http://127.0.0.1/User/AddEdit/7838fd9c-425c-4c98-b798-771bba10d9c1
This ID gets the data to populate the form values in a ViewModel, which populates the form
I am using jquery/ajax to save the form, which returns a Json result, indicating ok/error etc
In the View, I get the ID and use this in a hidden field which is set via jquery when the page loads and when the form is saved via ajax.
This seems a bit clunky, how do others do this?
in my opinion best solution is to create a partial view with all the fields and use it on add and edit view which are separate actions in controller. after you create user you can redirect to action edit. if you must / like use ajax you can reload div with form (change from user/add to user/edit/1). i might be wrong but i never see a code or example with one action in controller for add and edit.