How to create a dynamic form in MVC

This is a very simple task with controls in asp.net, but I don't know how to do this in MVC. I have a page where I want the user to enter the identifier of his employee. If employeeid is in the database, I want to remove the login and show the survey to fill out. If employeeid is not in the database, I want to show them a form to collect information about their employees. After they submitted their information, I want to show them a survey.

They can fill out several surveys, so I would like the survey to be sent to the same page with the ability to create a new survey or edit what they previously did. Every time they come to this page and type in the identifier of their employee, I want to show them a list of my previous polls with the possibility of creating a new one.

How to do it in MVC? Create a view and use partial data for the survey and registration form? I'm not sure how MVC handles this scenario best.

+4
source share
2 answers

You can easily change what is shown in the view based on the provided ViewMdel (or ViewBag if you use it). For example, something like:

@if (Model.HasEmployeeID) { <form> <!-- your form here --> </form> } else { <div class="survey"> <!-- your survey here --> </div> } 

For what you are going to use only once, you can just leave it all in one view. In order to be reused (or if you like this level of organization), you can make a form and / or view a partial view.

Based on your description, I would expect the review to at least be well suited for partial viewing.

+1
source

I would recommend that you study the MVC framework for web applications a little and start here ... http://www.asp.net/mvc

For a login script, check these messages http://msdn.microsoft.com/en-us/library/ff398049(v=vs.100).aspx http://www.codeproject.com/Articles/578374/AplusBeginner- 27splusTutorialplusonplusCustomplusF

I would have a structure like

http://myapp.com/surveys/ Actions-> (all, single creation, single update, single delete)

http://myapp.com/trainings Actions → (all, single creation, single update, single delete)

http://myapp.com/users/ Actions-> (create, update, delete)

Surveys are polls with actions ... Trainings are completed polls agreed with users ... and users are users ...

It could be a simple run of the mvc structure structure for the first snapshot ... devil is in the details =) ... as always ... But this should give you enough food to get started ...

NTN

+1
source

Source: https://habr.com/ru/post/1482159/


All Articles