Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. public class WebPages
  2. {
  3. [Key]
  4. public int WebPagesId { get; set; }
  5. public int ClientsId { get; set; }
  6. [ForeignKey("ClientsId")]
  7. public virtual Clients Clients { get; set;}
  8. public String ClientsName { get; set; }
  9. public String DomainName { get; set; }
  10. public String DomainEmails { get; set; }
  11. public String DomainUsers { get; set; }
  12. public String DomainPasswords { get; set; }
  13.  
  14. }
  15. }
  16.  
  17. public class WebPagesViewModel
  18. {
  19. public String DomainName { get; set; }
  20. public String DomainEmails { get; set; }
  21. public String DomainUsers { get; set; }
  22. public String DomainPasswords { get; set; }
  23. public int SelectedClient { get; set; }
  24. public IEnumerable<SelectListItem> Clients { get; set; }
  25. }
  26.  
  27. public ActionResult Create(WebPages model)
  28. {
  29.  
  30. var vm = new WebPagesViewModel
  31. {
  32.  
  33. Clients = new SelectList(db.ClientsList, "ClientsId", "ClientsName"),
  34.  
  35. };
  36.  
  37.  
  38. return View(vm);
  39. }
  40.  
  41. [HttpPost]
  42. [ValidateAntiForgeryToken]
  43.  
  44. public async Task<ActionResult> Create([Bind(Include = "DomainName,DomainEmails,DomainUsers,DomainPasswords,ClientsName,SelectedClient")] WebPagesViewModel model)
  45. {
  46.  
  47.  
  48. model.Clients = new SelectList(db.ClientsList, "ClientsId", "ClientsName");
  49. try
  50. {
  51. if (ModelState.IsValid)
  52. {
  53. model.WebPagesCreate();
  54.  
  55. return RedirectToAction("Index", "WebPages");
  56. }
  57.  
  58. }
  59. catch (Exception)
  60. {
  61. //Exception code
  62. }
  63.  
  64. return View(model);
  65. }
  66.  
  67. @model IncursusAccounting.Models.ViewModels.WebPagesViewModel
  68.  
  69. @{
  70. ViewBag.Title = "Create";
  71. }
  72.  
  73. <h2>Create</h2>
  74.  
  75. @using (Html.BeginForm())
  76. {
  77. @Html.AntiForgeryToken()
  78.  
  79. <div class="form-horizontal">
  80. <h4>WebPages</h4>
  81. <hr />
  82. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  83. <div class="form-group">
  84. <div class="col-md-10">
  85. @Html.DropDownListFor(m => m.SelectedClient, Model.Clients, "-Selecciona una opcion-", new { @class = "form-control" })
  86. @Html.ValidationMessageFor(m => m.SelectedClient)
  87. </div>
  88. </div>
  89. <div class="form-group">
  90. @Html.LabelFor(model => model.DomainName, htmlAttributes: new { @class = "control-label col-md-2" })
  91. <div class="col-md-10">
  92. @Html.EditorFor(model => model.DomainName, new { htmlAttributes = new { @class = "form-control" } })
  93. @Html.ValidationMessageFor(model => model.DomainName, "", new { @class = "text-danger" })
  94. </div>
  95. </div>
  96.  
  97. <div class="form-group">
  98. @Html.LabelFor(model => model.DomainEmails, htmlAttributes: new { @class = "control-label col-md-2" })
  99. <div class="col-md-10">
  100. @Html.EditorFor(model => model.DomainEmails, new { htmlAttributes = new { @class = "form-control" } })
  101. @Html.ValidationMessageFor(model => model.DomainEmails, "", new { @class = "text-danger" })
  102. </div>
  103. </div>
  104.  
  105. <div class="form-group">
  106. @Html.LabelFor(model => model.DomainUsers, htmlAttributes: new { @class = "control-label col-md-2" })
  107. <div class="col-md-10">
  108. @Html.EditorFor(model => model.DomainUsers, new { htmlAttributes = new { @class = "form-control" } })
  109. @Html.ValidationMessageFor(model => model.DomainUsers, "", new { @class = "text-danger" })
  110. </div>
  111. </div>
  112.  
  113. <div class="form-group">
  114. @Html.LabelFor(model => model.DomainPasswords, htmlAttributes: new { @class = "control-label col-md-2" })
  115. <div class="col-md-10">
  116. @Html.EditorFor(model => model.DomainPasswords, new { htmlAttributes = new { @class = "form-control" } })
  117. @Html.ValidationMessageFor(model => model.DomainPasswords, "", new { @class = "text-danger" })
  118. </div>
  119. </div>
  120.  
  121. <div class="form-group">
  122. <div class="col-md-offset-2 col-md-10">
  123. <input type="submit" value="Create" class="btn btn-default" />
  124. </div>
  125. </div>
  126. </div>
  127. }
  128.  
  129. <div>
  130. @Html.ActionLink("Back to List", "Index")
  131. </div>
  132.  
  133. public class DomainUser {
  134. public String Email { get; set; }
  135. public String User { get; set; }
  136. public String Password { get; set; }
  137. }
  138.  
  139. public ActionResult Index()
  140. {
  141. var initialData = new[] {
  142. new DomainUser { Email = "email@example.org", User = "ExampleUser", Password="ExamplePassword" }
  143. };
  144. return View(initialData);
  145. }
  146.  
  147. <h2>Domain Users</h2>
  148.  
  149. <% using(Html.BeginForm()) { %>
  150. <div id="domainUserRows">
  151. <% foreach (var item in Model)
  152. Html.RenderPartial("DomainUser", item);
  153. %>
  154. </div>
  155.  
  156. <input type="submit" value="Finished" />
  157. <% } %>
  158.  
  159. <div class="domainUserRow">
  160. <% using(Html.BeginCollectionItem("DomainUser")) { %>
  161. Email: <%= Html.TextBoxFor(x => x.Email) %>
  162. User: <%= Html.TextBoxFor(x => x.User) %>
  163. Password: <%= Html.TextBoxFor(x => x.Password) %>
  164. <% } %>
  165. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement