I was trying to use Html Display For Template for looping through a Model data. Inside my Display template, I wanted to use an EditorFor template that would display a different set of data, In doing so, I was running into issues where my child model was empty. Upon playing around and getting guidance from David, I was able to make this to work. Below, please find my updated working solution.
UPDATE (Correct solution)
public class TargetingAreaViewModel
{
public int DealerId { get; set; }
public int OrderId { get; set; }
public List<TargetingAreaOrderItemViewModel> TargetingAreaOrderItems { get; set; }
public TargetingAreaViewModel()
{
this.TargetingAreaOrderItems = new List<TargetingAreaOrderItemViewModel>();
}
}
public class TargetingAreaOrderItemViewModel
{
public int OrderItemId { get; set; }
public int PackageMediaTypeId { get; set; }
public string PackageMediaTypeHeader { get; set; }
public string MediaTypeDesc { get; set; }
public string TargetingAdditonalInfo { get; set; }
public List<TargetingAreaItemViewModel> TargetingAreaItems { get; set; }
public TargetingAreaOrderItemViewModel()
{
this.TargetingAreaItems = new List<TargetingAreaItemViewModel>();
}
}
public class TargetingAreaItemViewModel
{
public int OrderItemId { get; set; }
public int PackageMediaTargetingFieldId { get; set; }
public string TargetingAreaFieldTitle { get; set; }
public string TargetingValue { get; set; }
public bool IsEnabled { get; set; }
public bool IsRequired { get; set; }
public string Comment { get; set; }
}
Parent View
#model Models.TargetingAreaViewModel
#{
ApplicationContext.Current.PageTitle = "Targeting Info";
Layout = "~/Views/Shared/MainLayout.cshtml";
}
#using (Html.BeginForm("OrderItemTargetingInfo", "Home", FormMethod.Post, new { #class = "form-horizontal" }))
{
#Html.DisplayFor(m => m.TargetingAreaOrderItems)
<div class="col-sm-12">
<div class="pull-right">
<input id="Submit" type="submit" value="Submit" class="btn btn-primary" />
</div>
</div>
}
DisplayFor Template View
#model Models.TargetingAreaOrderItemViewModel
<div class="row">
<div class="col-sm-12">
<div class="col-sm-12 btn-primary" style="margin-bottom: 10px; margin-top: 10px;">
#Html.Label(Model.MediaTypeDesc, new { #style = "font-weight: bold; padding-top: 10px; font-size: 18px;" })
#Html.HiddenFor(m => m.OrderItemId)
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
#Html.Raw(Model.PackageMediaTypeHeader)
</div>
</div>
<br />
<div class="row">
<div class="col-sm-12">
#Html.EditorFor(m => m.TargetingAreaItems)
</div>
</div>
<br />
<div class="row">
<div class="col-md-12">
<div class="form-group">
#Html.Label("Additional Info:", new { #class = "control-label col-md-2" })
<div class="col-md-6">
#Html.TextAreaFor(m => m.TargetingAdditonalInfo, new { #class = "form-control" })
</div>
</div>
</div>
</div>
Now, I am able to display the data, get the data out of my model on Post. Works great!!
In your parent views you are only passing in the TargetingAreaOrderItems of the model but the child view is expecting a TargetingAreaViewModel. Instead you should pass in the entire model:
#Html.DisplayFor(m => m)
Related
I have simple code first model (image: https://ufile.io/7c52a)
I have a problem, when I want to add a new bill. When I add a new bill, I also want to add products on that bill (insert data into Pr_bi table).
My bill entity:
public class Bill : Entity
{
public string Number { get; set; }
public DateTime TimeStamp { get; set; }
public virtual Customer Customer { get; set; }
public virtual ICollection<Product_Bill> Product_Bill { get; set; }
}
My product entity:
public class Product : Entity
{
public string Name { get; set; }
public virtual ICollection<Product_Bill> Product_Bill { get; set; }
}
My pr_bi entity:
public class Product_Bill : Entity
{
public int Quantity { get; set; }
public virtual Bill Bill { get; set; }
public virtual Product Product { get; set; }
}
I create create view model like that:
#using (Html.BeginForm("Create", "Bill", FormMethod.Post, new { #class = "form-horizontal" })){
#Html.HiddenFor(m => m.ID)
<div class="form-group">
<label class="col-sm-2 control-label">Bill number:</label>
<div class="col-sm-6">
#Html.TextBoxFor(m => m.Number, new { #class = "form-control" })
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Payed:</label>
<div class="col-sm-6">
#Html.EditorFor(x => x.Payed)
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Customer:</label>
<div class="col-sm-6">
#Html.DropDownListFor(m => m.Customer.ID, ViewData["Customers"] as SelectList, new { #class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-6"><input type="submit" value="Shrani" class="btn btn-default" /></div>
</div>}
How can I add product on that bill inside that create view for a bill?
What do I have and what I like:
Screen
Thank you and have a nice day!
I have a weird situation where we have this view model:
public class AddCommunicationViewModel
{
public Guid Id { get; set; }
public Guid ParentCommunicationGroupId { get; set; }
public Guid ParentCommunicationGroupCampaignId { get; set; }
public List<SelectListItem> CommunicationTypes { get; set; }
public CommunicationType SelectedCommunicationTypeId { get; set; }
[AllowHtml]
public string Subject { get; set; }
[AllowHtml]
public string Content { get; set; }
public string Reference { get; set; }
public bool AttachDemand { get; set; }
public int CommunicationSortingIndex { get; set; }
public string CommunicationGroupName { get; set; }
public AddCommunicationViewModel()
{
CommunicationTypes = new List<SelectListItem>();
}
}
Now, I have a very simple form (using Html.BeginForm) which posts to the controller:
#using (Html.BeginForm("UpdateSavedCommunication", "Communication", FormMethod.Post, new { id = "saveCommunication" }))
{
#Html.HiddenFor(c => c.ParentCommunicationGroupCampaignId)
#Html.HiddenFor(c => c.ParentCommunicationGroupId)
#Html.HiddenFor(c => c.Id)
<div class="form-group">
#Html.LabelFor(c => c.SelectedCommunicationTypeId)
#Html.DropDownListFor(c => c.SelectedCommunicationTypeId, Model.CommunicationTypes, new { #class = "form-control" })
</div>
<div class="div_subject form-group email">
#Html.LabelFor(c => c.Subject)
#Html.TextBoxFor(c => c.Subject, new { #class = "form-control" })
</div>
<div class="div_content form-group mb-3">
#Html.LabelFor(c => c.Content)
<div class="card-body">
<form class="form-horizontal form-bordered">
<div class="form-group row">
<div class="col-sm-12">
<textarea name="Content" id="summernote" class="summernote" data-plugin-summernote data-plugin-options='{ "height": 280, "codemirror": { "theme": "ambiance" } }'>
#Html.Raw(Model.Content)
</textarea>
</div>
</div>
</form>
</div>
</div>
<div class="div_reference form-group email">
#Html.LabelFor(c => c.Reference)
#Html.TextBoxFor(c => c.Reference, new { #class = "form-control" })
</div>
<div class="div_attachdemand form-group mb-3">
<div>
#Html.LabelFor(c => c.AttachDemand)
#Html.CheckBoxFor(c => c.AttachDemand)
</div>
</div>
<input type="submit" class="btn btn-success" value="Gem" onclick="document.getElementById('saveCommunication').submit();" />
}
The reason my "Content" variable is a bit weird, is because I user the Summernote editor. When I click the submit button all posts fine without any JavaScript errors.
However, now the weird stuff comes.
My variables: Reference and AttachDemand is NOT posted to server. Looking at Fiddler, I can see this is the post:
ParentCommunicationGroupCampaignId=00000000-0000-0000-0000-000000000000&ParentCommunicationGroupId=00000000-0000-0000-0000-000000000000&Id=2953bc1b-49e5-4f65-8159-1c53de5c82e8&SelectedCommunicationTypeId=2&Subject=&Content=++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3EHej%C2%A0*%7CNAME%7C*.%C2%A0%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3E*%7CCREDITORNAME%7C*+har+bedt+os+inddrive+din+g%C3%A6ld+hos+dem.+Der+er+tale+om+en+g%C3%A6ld+p%C3%A5%3C%2Fspan%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3E%C2%A0%3C%2Fspan%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3E*%7CDEMANDLINK%7C*+kr%2C+som+du+bedes+betale.%3Cbr%3EVi+har+vedh%C3%A6ftet+kravet+i+dette+brev+p%C3%A5+e-mail.%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3EDet+er+vigtigt+at+du+betales+denne+g%C3%A6ld+hurtigst+muligt%2C+for+at+undg%C3%A5+at+der+p%C3%A5l%C3%B8ber+ekstra+renter+samt+en+registrering+hos+RKI+og+som+videre+konsekvens+sendt+til+fogedretten.%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3ESE+DIN+SAG+OG+BETAL%3A+*%7CDEMANDLINK%7C*%C2%A0%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3E%3Cbr%3E%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3EVh%3Cbr%3E%3C%2Fspan%3E%3C%2Fp%3E%0D%0A++++++++++++++++++++++++%0D%0A++++++++++++++++++++++++%0D%0A++++++++++++++++++++++++%0D%0A++++++++++++++++++++++++%0D%0A++++++++++++++++++++++++&files=
Or in a view for humans:
So my challenge is: where is my Reference and AttachDemand ?
Now, if I move these two ABOVE the content editor, they work. So it seems that the Content is breaking because it sends some pretty cool HTML.
So any idea how to "make" this work? I guess I need to somehow escape the input in some smart way? I have added [AllowHtml] on the content attribute because it will contain HTML, but more than that?
Your view has nested forms which is invalid html and not supported (and depending on the browser and version, you may see different results).
Remove the inner <form class="form-horizontal form-bordered"> surrounding the textarea to ensure all from controls are serialized and sent in the request.
I have this form in MVC Razor . The html is quite long so I am posting the area where I want to work
these are the checkboxes which are populated as service packages
The flow is the user will upload a photo and when proceeds to the next step it goes to a page where he will be selecting service for each photo if he has uploaded 3 photos the three photos will be having the same service
listing but different order IDS
I want is that when a user select services for a specific order means a specific order has multiple services . I want to map it so that Model List will be feteched in the Controller and I can easily insert in the database
this is the HTML:
#using (Html.BeginForm("PlaceOrder", "User", FormMethod.Post, new { id="ServiceForm",#class = "form-horizontal
white-clr", role = "form" }))
{
<!--If user has uploaded a single photo or multiple photo -->
<div class="window-for-choose-service">
#if (ViewBag.OrdersList != null)
{
int i= 1;
foreach (var d in ViewBag.OrdersList)
{
<div class="row">
<div class="col-sm-3 col-md-3 col-lg-3">
<img src="#d.ThumbnailPath" class="img-thumbnail img-responsive" width="250">
</div>
<div class="col-sm-9 col-md-9 col-lg-9">
<form class="white-clr" role="form">
<div class="form-group">
<label for="name">Description</label>
<textarea class="form-control" rows="4"></textarea>
</div>
</form>
</div>
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="panel-group" id="accordion_#d.ID">
<div class="panel panel-primary">
#foreach (var Services in ViewBag.ServicePackages)
{
int cID = Services.ID + d.ID;
//int rndNumber = Convert.ToInt32(TimeSpan.FromSeconds(new Random().Next(0,
11221)).ToString("hmsf"));
if (Services.ServiceParentID == null)
{
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion_#d.ID"
href="#collapseOne_#cID">
#Services.ServiceName
</a>
</h4>
</div>
<div id="collapseOne_#cID" class="panel-collapse collapse in">
<div class="panel-body">
<div>
<div class="table-responsive">
#foreach (var child in Services.ft_service_packages1)
{
//string ness = "ServiceSelected[" + #d.ID + "]";
<div style="width:auto;min-width:250px;float:left; padding:4px; display:inline-block">
<div style="float:left;padding-right:5px;">
<label for="inlinecheckbox_#child.ID">
#Html.CheckBoxFor(m => m.ServiceSelect, new { id = "inlinecheckbox_" +
#child.ID, price_attr = "#child.ServicePrice"})
#Html.HiddenFor(m => m.UploadOrderID, new { Value = #d.ID })
</label>
</div>
<div style="padding-left:2px;">#child.ServiceName</div>
</div>
}
</div>
</div>
</div>
</div>
i++;
}
}
</div>
</div>
</div>
<div class="col-sm-12 col-md-12 col-lg-12"><p class="text-right font-blue"><b> Price $
0.0</b></p> </div>
</div>
}
}
The Html is genereting perfectly fine . But the thing is not getting anything in the controller regarding the model
Model is listed below
using System;
using System.Collections.Generic;
public partial class ft_order_itemized
{
public int ID { get; set; }
public int UploadOrderID { get; set; }
public int ServiceSelected { get; set; }
public decimal ServiceCharges { get; set; }
public System.DateTime ServiceSelectedDate { get; set; }
public Nullable<int> OrderID { get; set; }
public bool ServiceSelect { get; set; }
public virtual ft_orders ft_orders { get; set; }
public virtual ft_service_packages ft_service_packages { get; set; }
public virtual ft_uploads_orders ft_uploads_orders { get; set; }
}
My Controller :
[HttpPost]
public ActionResult PlaceOrder(ICollection<ft_order_itemized> Orders)
{
if (Orders.Count > 0)
{
}
// ICollection Allstrings = Orders["Service"].ToList();
return View();
}
I am trying to add datas to two different tables using same view and controller. But I am stuck. I am new at MVC, please let me know what did I wrong.Dto Model, Controller, Facade, Servicei,View and Entity Model as follows.
I get this Error
The model item passed into the dictionary is of type 'LibOrganizerEntity.Entity.OrgProje', but this dictionary requires a model item of type 'LibOrganizerSvc.Dto.ProjeEkleDto'.
Entity Models
[Table("KAR_PROJE")]
public class OrgProje
{
[Key, Required]
[Column("SIRA_NO")]
public int ID { get; set; }
[Column("ACIKLAMA")]
public string Aciklama { get; set; }
[Column("PLANLANAN_BASLANGIC_TARIHI")]
public DateTime? PlanlananBaslangicTarihi { get; set; }
[Column("PLANLANAN_BITIS_TARIHI")]
public DateTime? PlanlananBitisTarihi { get; set; }
[Column("GERCEKLESEN_BASLANGIC_TARIHI")]
public DateTime? GerceklesenBaslangicTarihi { get; set; }
[Column("GERCEKLESEN_BITIS_TARIHI")]
public DateTime? GerceklesenBitisTarihi { get; set; }
[Column("SILINME_TARIHI")]
public DateTime? SilinmeTarihi { get; set; }
[Column("YONETICI_ID")]
public int? YoneticiId { get; set; }
[ForeignKey("YoneticiId")]
public virtual OrgPersonel OrgPersonel { get; set; }
public virtual OrgProjeButce OrgProjeButce { get; set; }
public virtual OrgButce Butce { get; set; }
}
[Table("KAR_PROJE_BUTCE")]
public class OrgProjeButce
{
[Key, Required]
[Column("ID")]
public int ID { get; set; }
[Column("BUTCE_ID")]
public int ButceId { get; set; }
[Column("BUTCE_TUTAR")]
public float ButceTutar { get; set; }
[Column("GERCEKLESEN")]
public float? Gerceklesen { get; set; }
[ForeignKey("ButceId")]
public virtual OrgButce OrgButce { get; set; }
}
Dto Model
public class ProjeEkleDto
{
public string Aciklama { get; set; }
public DateTime? PlanlananBaslangicTarihi { get; set; }
public DateTime? PlanlananBitisTarihi { get; set; }
public DateTime? GerceklesenBaslangicTarihi { get; set; }
public DateTime? GerceklesenBitisTarihi { get; set; }
public DateTime? SilinmeTarihi { get; set; }
public string YoneticiAdi { get; set; }
public string YoneticiSoyadi { get; set; }
public string YoneticiId { get; set; }
public int ButceId { get; set; }
public string ButceAdi { get; set; }
public float ProjeButceTutari { get; set; }
public virtual IEnumerable<OrgPersonel> Proje { get; set; }
public virtual IEnumerable<OrgProjeButce> Butce { get; set; }
}
Controller
public ActionResult ProjeEkle()
{
return View();
}
[HttpPost]
public ActionResult ProjeEkle(OrgProje model)
{
try
{
svc.ProjeEkle(model);
return RedirectToAction("Index", "Home");
}
catch(Exception ex)
{
}
return View(model);
}
Service
public void ProjeEkle(OrgProje proje)
{
var dto = new ProjeFacade(db);
dto.ProjeEkle(proje);
}
Facade
public void ProjeEkle(OrgProje proje)
{
db.OrgProjeler.Add(proje);
db.SaveChanges();
}
View
#model LibOrganizerSvc.Dto.ProjeEkleDto
#{
ViewBag.Title = "ProjeEkle";
Layout = "~/Views/Shared/_Layout.cshtml";
}
#using (Html.BeginForm())
{
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Proje Ekle</h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-6">
<h4 class="heading_a">Proje Detayları</h4>
<div class="form-group" style="width: 47%; float: left">
<label for="reg_input">Proje Adı</label>
<input type="text" id="#Html.IdFor(x => x.Aciklama)" class="form-control">
</div>
<div class="form-group" style="width: 47%; float: right;">
<label for="reg_input">Proje Yöneticisi</label>
<select id="#Html.IdFor(x => x.YoneticiId)" name="chn_country" class="form-control">
#Html.Action("_PersonelleriGetir", "Ortak")
</select>
</div>
<div class="form-group" style="width: 47%; float: right;">
<label for="reg_input">Proje Bütçe Türleri</label>
<select id="#Html.IdFor(x => x.ButceAdi)" name="#Html.IdFor(x => x.ButceAdi)" class="form-control">
#Html.Action("_ButceleriGetir", "Ortak")
</select>
</div>
<div class="col-sm-6" style="padding-left: 0;">
<label for="reg_input">Proje Bütçesi</label>
<input type="text" id="#Html.IdFor(x => x.ProjeButceTutari)" class="form-control" name="#Html.IdFor(x => x.ProjeButceTutari)">
<span class="help-block">2000 ₺</span>
</div>
</div>
<div class="col-sm-6">
<h4 class="heading_a">Proje Zaman Ayarları</h4>
</div>
<div class="col-sm-3">
<label for="reg_input">Planlanan Başlama Tarihi</label>
<div class="input-group date ebro_datepicker" data-date-format="dd-mm-yyyy" data-date-autoclose="true">
<input class="form-control" type="text" id="#Html.IdFor(x => x.PlanlananBaslangicTarihi)">
<span class="input-group-addon"><i class="icon-calendar"></i></span>
</div>
</div>
<div class="col-sm-3">
<label for="reg_input">Planlanan Bitiş Tarihi</label>
<div class="input-group date ebro_datepicker" data-date-format="dd-mm-yyyy" data-date-autoclose="true">
<input class="form-control" type="text" id="#Html.IdFor(x => x.PlanlananBitisTarihi)">
<span class="input-group-addon"><i class="icon-calendar"></i></span>
</div>
</div>
<div class="col-sm-3">
<label for="reg_input" style="margin-top: 15px;">Gerçekleşen Başlama Tarihi</label>
<div class="input-group date ebro_datepicker" data-date-format="dd-mm-yyyy" data-date-autoclose="true">
<input class="form-control" type="text" id="#Html.IdFor(x => x.GerceklesenBaslangicTarihi)">
<span class="input-group-addon"><i class="icon-calendar"></i></span>
</div>
</div>
<div class="col-sm-3">
<label for="reg_input" style="margin-top: 15px;">Gerçekleşen Bitiş Tarihi</label>
<div class="input-group date ebro_datepicker" data-date-format="dd-mm-yyyy" data-date-autoclose="true">
<input class="form-control" type="text" id="#Html.IdFor(x => x.GerceklesenBitisTarihi)">
<span class="input-group-addon"><i class="icon-calendar"></i></span>
</div>
</div>
<div style="float: left; margin-top: 20px; width: 90%; position: relative; left: 15px;">
<input type="submit" class="btn btn-default btn-lg" value="Kaydet" />
</div>
</div>
</div>
</div>
</div>
</div>
}
As the error message indicates, you are passing a class of type OrgProje to a view that requires a view of type ProjeEkleDto.
Your error occurs in this action method:
[HttpPost]
public ActionResult ProjeEkle(OrgProje model)
{
try
{
svc.ProjeEkle(model);
return RedirectToAction("Index", "Home");
}
catch(Exception ex)
{
}
return View(model); // Passing a view model of the wrong type to the view
}
Either pass a view model of type ProjeEkleDto back to the view instead of your model of type OrgProje, or create a different view that accepts a view model of type OrgProje.
In your view Change -
#model LibOrganizerSvc.Dto.ProjeEkleDto
to
#model NameSpace.ProjeEkleDto
I am not sure about which namespace to be used, but you replace NameSpace with appropriate one.
In my ASP.Net MVC3 Razor project i have to implement a customer registration form(Screen Shot Attached).In that form , a single entity (say :purpose of doing DMIt) contains more than one answer.So i use checkbox to select the multiple or single answer.I have the view page and also a Model.How to code the View page to select multiple checkbox and also in Controller.
Controller Code
public ActionResult CustomerRegistration()
{
return View();
}
Model Code
namespace Elixir.Models
{
[Table("tbl_ElixirCustomer")]
public class Customer
{
[Key]
public int CusId { get; set; }
public string Name { get; set; }
public int age { get; set; }
public int Gender { get; set; }
public string FathName { get; set; }
public string MothName { get; set; }
public string OrgSchooName { get; set; }
public string Address { get; set; }
public string city { get; set; }
public string State { get; set; }
public string PIN { get; set; }
public string tele { get; set; }
public string Mob { get; set; }
public string Email { get; set; }
public string Web { get; set; }
public string Purpose { get; set; }
public string brief { get; set; }
}
public class CustomerViewModel
{
public string Purpose { get; set; }
public int Id { get; set; }
public bool IsChecked { get; set; }
}
}
View Code
<div class="col-lg-10">#Html.TextBoxFor(Model => Model.Mob, new { #class = "form-control" })</div>
<label class="col-lg-2 control-label">
Email</label>
<div class="col-lg-10">#Html.TextBoxFor(Model => Model.Email, new { #class = "form-control" })</div>
<label class="col-lg-2 control-label">
Web Site</label>
<div class="col-lg-10">#Html.TextBoxFor(Model => Model.Web, new { #class = "form-control" })</div>
<label class="col-lg-2 control-label">
Purpose of doing DMIT</label>
<div class="col-lg-10">
<div class="styled-chekbox">
<input type="checkbox" checked class="icheck-box-flat">
</div>
<span class="checkbox-label">Career Planning</span>
<div class="styled-chekbox">
<input type="checkbox" checked class="icheck-box-flat">
</div>
<span class="checkbox-label">Personel</span>
<div class="styled-chekbox">
<input type="checkbox" checked class="icheck-box-flat">
</div>
<span class="checkbox-label">Relationship</span>
<div class="styled-chekbox">
<input type="checkbox" checked class="icheck-box-flat">
</div>
<span class="checkbox-label">Parenting</span>
<div class="styled-chekbox">
<input type="checkbox" checked class="icheck-box-flat">
</div>
<span class="checkbox-label">Activity Plan for children</span>
<div class="styled-chekbox">
<input type="checkbox" checked class="icheck-box-flat">
</div>
<span class="checkbox-label">Stress Management</span>
</div>
<label class="col-lg-2 control-label">
Any Challenges</label>
<div class="col-lg-10">#Html.TextAreaFor(model => model.brief, new { #class = "tinymce-simple span12", #row = "170", #cols = "45", #width = "40%" })</div>
<div class="col-lg-2 control-label"></div>
<div class="col-lg-10">
#*<input type="button" class="" />*# #* <button type="submit" class = "btn btn-success">#Html.ActionLink("Save", "EmployeeRegistration", "Home")</button>*#
#* <button type="submit" >#Html.ActionLink("Save", "EmployeeRegistration", "Home", new { #class = "btn btn-success" })</button>*#
<input type="submit" class="btn btn-success" value="Save" />
<button class="btn btn-success">
Clear</button>
<button class="btn btn-success">
Cancel</button>
</div>
In CustomerViewModel you can have separate properties for every option
public bool CareerPlanning { get; set; }
public bool Personal{ get; set; }
public bool RelationShip{ get; set; }
and So on.....
Then in view you can have field for these properties
#Html.CheckBoxFor(Model => Model.CareerPlanning )<span> Career Planning </span>
#Html.CheckBoxFor(Model => Model.Personal)<span> Personal </span>
#Html.CheckBoxFor(Model => Model.RelationShip) <span> RelationShip</span>
and So on.....
Now in controller you need to modify Purpose depending on all checkbox value
StringBuilder sb=new StringBuilder();
if(model.CareerPlanning)
sb.Append("Carrer Planning");
if(model.Personal)
sb.Append("-Personal");
and so on....
and at the end
model.Purpose=sb.ToString();
Create a Boolean property in model
Model:
public String Question{ get; set; }
public Boolean Options{ get; set; }
public String OptionContent{ get; set; }
...so on
Pass this model into the view and then use EditorFor html helper.
#using (Html.BeginForm("actionname", "Home", FormMethod.Post, null)){
<div>
#Html.LabelFor(model => model.Question)
</div>
<div>
#Html.EditorFor(model => model.Option)
#Html.LabelFor(model => model.OptionContent)
</div>
}