I´m new in asp.net, and I'm using EF, and I want to implement BeginCollectionItem into my application, so in my model I have DomainEmails,DomainPasswords and DomainUsers can be added dynamically when I creating a new WebPage using somthing like "Add new" and ask me for another DomainEmails,DomainPasswords and DomainUsers
There is my model:
public class WebPages
{
[Key]
public int WebPagesId { get; set; }
public int ClientsId { get; set; }
[ForeignKey("ClientsId")]
public virtual Clients Clients { get; set;}
public String ClientsName { get; set; }
public String DomainName { get; set; }
public String DomainEmails { get; set; }
public String DomainUsers { get; set; }
public String DomainPasswords { get; set; }
}
}
Viewmodel:
public class WebPagesViewModel
{
public String DomainName { get; set; }
public String DomainEmails { get; set; }
public String DomainUsers { get; set; }
public String DomainPasswords { get; set; }
public int SelectedClient { get; set; }
public IEnumerable<SelectListItem> Clients { get; set; }
}
Get Controller:
public ActionResult Create(WebPages model)
{
var vm = new WebPagesViewModel
{
Clients = new SelectList(db.ClientsList, "ClientsId", "ClientsName"),
};
return View(vm);
}
Post Controller:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "DomainName,DomainEmails,DomainUsers,DomainPasswords,ClientsName,SelectedClient")] WebPagesViewModel model)
{
model.Clients = new SelectList(db.ClientsList, "ClientsId", "ClientsName");
try
{
if (ModelState.IsValid)
{
model.WebPagesCreate();
return RedirectToAction("Index", "WebPages");
}
}
catch (Exception)
{
}
return View(model);
}
Thankyou in advance!
What I have tried:
I search how to do that but examples are to different than I want to do, If any one can help me I really appreciate it!