I have a two stage process:
A user completes an application form which is stored in a db and an internal team validates the data at which stage the user is send an email link asking them to complete the application.
A page is displayed to the user containing all of the information that they originally supplied with a confirmation button.
My problem is on step 2, I'm populating a model on page load and displaying this information to the user but when the user submits the form the model being posted back is empty.
If I use #Html.TextBoxFor(m => m.name) etc. then the model will still contain the value of the property but I all I need to do is display the values to them rather than give them the opportunity to amend them (they're actually not allowed to amend them at this stage).
Is there any helper that I can use for this or is there no way around this?
Thanks,
C
Related
I have a web page with multiple separate tabs, all exist in DOM, switching between them is entirely client-side. Each tab contains an ajax form for editing data of a selected app user. For eg. first tab lets you edit name, surname, ..., second tab lets you edit address. Each tab has a save button and each time only properties of current tab are propagated to the DB. All works well :)
BUT, of course, each tab needs PK of the user (user.Id) in question. Its passed to controller via a hidden field
<input type="hidden" asp-for="Id" />, so HTML DOM contains more than one element with the same id and browsers complain.
I know that I could manually set the name/id of these input fields, and manually map them on the controller side, but model binder could do this for me, its nice and clean.
public async Task<IActionResult> EditGeneralData([Bind(GeneralDataBindFieldNames)]AppUser appUser)
Is there a nice & simple way to achieve this? Should I simply forget about the browser warning as I will be careful when/if using getElementById? Whats your take on this?
Yeah... not really the answer I was looking for, but it should suffice. It turns up that the content of these tabs is related to one another. So all the tabs cannot exist in the DOM at the same time, and switching between them cannot be entirely client side.
Now, tab click loads tab content on demand, so theres no multiple input fields in the DOM anymore. Only one tab at a time means only one input field at a time :)
I have a MVC5 page that is shows Customer's information in Text box then you can update some of the data and push Update button. it is going to update info but it is not showing the new value after pushing the update button, you have to leave a page and comeback to see a new value.
UpdateCustomer and (presumably) UpdatePassword should not return a View but instead should return a RedirectResponse back to the [HttpGet] version of the Edit action. This is known as a Post-Redirect-Get pattern and is the preferred way of redisplaying the same page the user just edited. By returning the view with the same model that was posted you're just showing the user what they originally typed in. You're also leaving yourself open to multi-postback situations if the user tries refreshing their browser.
You also seem to be fighting the framework. If you've got two buttons on the page that perform two different actions you should have two forms that each POST to a different controller action.
I have a site that manages a database.
Lets say the users enter information about people (height, weight, name etc...)
A lot of people are entered each day and the height range is quite small so if a user entered a person with a certain height I want it to auto complete next time he enters a person.
(like most login forms where you click a textbox and it shows your recent entered login info and when you start typing it auto completes you).
I am using MVC 4 and the person entry is not within a form. When a user clicks save it uses ajax to save.
I know it works with forms but how can I do it on certain textboxes which arent in a form.
The jQuery autocomplete solution doesn't require fields to be in a form.
If you look at the source code of the sample, the previous data is stored as a JavaScript array. You could store previous entries for each user in a database and then use this data to build an JSON array that can be passed via a view-model to the view and then use jQuery.parseJSON() to render it straight into place in the JavaScript.
This is a very simple thing to do with controls in asp.net, but I have no idea how to accomplish it in MVC. I have a page where I want the user to type in his employee id. If the employeeid is in the database, I want to remove the log in and show a survey for them to fill out. If the employeeid is not in the database, I want to show them a form to collect their employee information. After they submit their information, I want to show them the survey.
They can fill out several surveys, so I would like to have the survey submit to the same page with the option of creating a new survey or editing one they have previously done. Any time they come to this page and type in their employee id, I want to show them a list of their previous surveys with the option to create a new one.
How can I accomplish this in MVC? Do I create a view and use partials for the survey and log in form? I'm not sure how MVC best handles this sort of scenario.
You can change what is shown in the view easily based on the supplied ViewMdel (or ViewBag if you use that). For example something like:
#if (Model.HasEmployeeID)
{
<form>
<!-- your form here -->
</form>
}
else
{
<div class="survey">
<!-- your survey here -->
</div>
}
For something that you are only going to use once, you can just leave it all in one view. For something that will be reusable (or if you just like that level of organization) you could make the form and/or survey a partial view.
Based on your description I would expect the survey at least to be well suited for a partial view.
I would recomend that you research a little bit on the MVC pattern for web applications
and start here...
http://www.asp.net/mvc
For the login scenario check these post out
http://msdn.microsoft.com/en-us/library/ff398049(v=vs.100).aspx
http://www.codeproject.com/Articles/578374/AplusBeginner-27splusTutorialplusonplusCustomplusF
I would general have a structure like this
http://myapp.com/surveys/ Actions-> (all, single create, single update, single delete)
http://myapp.com/trainings Actions ->(all, single create, single update, single delete)
http://myapp.com/users/ Actions-> (create, update, delete)
Surveys are the surveys with the actions... Trainings are the filled out surveys aligned to the users... and users are the users...
This could be a simple run down of how to structure the mvc routs for the first shot... devil is in the details =)... like always ...
But this should give u enough food to start...
HTH
I have an MVC application in which I create a search page to find projects I've created. Once the user enters the search criteria, the data is passed back to the controller as a model object and I take this data to search for any projects that match. The search page is redisplayed with the original criteria the user entered plus any projects that were found.
The user can now go an click on a row (the results of their search) and edit that data on another page. When the user hits the save button (on the other page), I save the data and go back to the search page. I don't have the original data (the search model object) to redisplay. How do I get it back? I'm thinking that I should just thorugh my model object that I got when the method was called through the controller into my session object and then retrieve it when I come back to the search page. Is there a more elegant solution to getting the data from the model object back when I return to the search page?
You can use TempData["whatevever"]= yourObject and the data there will exist until it is read the next time and then it is removed. Its like the session object, but is removed after you read it.