I
I
isxaker2013-10-26 20:57:19
JavaScript
isxaker, 2013-10-26 20:57:19

How to create a dynamically changeable entity creation form?

For example I have two classes in the model

public class Book<br>
{<br>
public string Title {get;set;}<br>
public IEnumerable<Author> Authors {get;set;}<br>
}<br>
<br>
public class Author<br>
{<br>
public string FirstName {get;set;}<br>
public string LastName {get;set;}<br>
}<br>


I want to create a form for creating new books, where you can add multiple authors one by one at once. How are such tasks solved? Tell me just which way to dig.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gleb_kudr, 2013-10-27
@gleb_kudr

If I understood the question correctly, then you are asking how you can organize this on the frontend.
You need to google towards "js multiselect dropdown".

N
Nikolai Turnaviotov, 2013-10-28
@foxmuldercp

Well, this is solved in mvc quite simply.
google towards editor(view)template for custom object
in /views/shared/ create folder editortemplates
in it put view to edit your model author
@model YourApp.Models.Author
Html .EditorFor(model => model.FirstName)
Html .EditorFor (model => model.LastName)
in the Create/edit views, where you want to draw controls for the author fields from the custom view, write
Html .EditorFor(model => model.Author) above
, what you have to do
to add the first author immediately to the form You need to give an already created object of the book class
// http.get to the create view
public ActioResult Create()
{
Book newbook = New Book();
IEnumerable newbook.authors = new IEnumerabe();
newbook.authors.Add(new Author());
returnView(newbook);
}
this will save you a bunch of crap
further, you still need a toad script that adds and removes lines from the dom element of the page before sending it to the server.
I drew my crutch with the help of my comrades (but my goal is to learn mvc / html / js), you can look for the necessary library in nuget's.
Or I can share mine.
although I already have plans to write a video course on how to write complex applications in mvc, otherwise the mvc3 / 4 basic framework is utterly dull and goes through beer in half an hour.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question