I currently have a data model that was generated from an existing database utilizing Entity Framework 6 (ASP.NET MVC 5). I'm currently working with two data tables: Contracts and Employees. They both are related to the Company table, so each table has CompanyID as a foreign key. When I scaffolded the Create Contract view, it currently has drop down lists for EmployeeID and CompanyID. What I'm trying to do is have the user select the CompanyID and only show the Employees that are tied to that Company.
I've tried using jQuery's getJSON method, but it's returning a 500 error due to a circular reference as I'm returning a JSON serialized Employee object which has a reference to Company (causing the circular reference error).
The Employee Model:
public partial class Employee
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Employee()
{
this.Contracts = new HashSet<Contract>();
this.HoleLoggings = new HashSet<HoleLogging>();
}
public int EmployeeID { get; set; }
public int CompanyID { get; set; }
public string Name { get; set; }
public string Department { get; set; }
public virtual Company Company { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Contract> Contracts { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<HoleLogging> HoleLoggings { get; set; }
}
The Contracts Model:
public partial class Contract
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Contract()
{
this.ContractDetails = new HashSet<ContractDetail>();
this.Platforms = new HashSet<Platform>();
this.ShiftReports = new HashSet<ShiftReport>();
}
public int ContractID { get; set; }
public int EmployeeID { get; set; }
public int CompanyID { get; set; }
public Nullable<System.DateTime> StartDate { get; set; }
public Nullable<System.DateTime> EndDate { get; set; }
public Nullable<bool> IsApproved { get; set; }
public virtual Company Company { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<ContractDetail> ContractDetails { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Platform> Platforms { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<ShiftReport> ShiftReports { get; set; }
public virtual Employee Employee { get; set; }
}
Here's the ActionMethod in my Contracts Controller:
public JsonResult GetEmployees(int id)
{
List<Employee> employees = new List<Employee>();
var employeeList = from e in db.Employees
where (e.CompanyID == id)
select e.
employees.AddRange(employeeList);
return Json(employees, JsonRequestBehavior.AllowGet);
}
The View's form:
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Contract</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(model => model.CompanyID, "CompanyID", htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.DropDownList("CompanyID", null, htmlAttributes: new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.CompanyID, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.EmployeeID, "EmployeeID", htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.DropDownList("EmployeeID", new SelectList(string.Empty, "Value", "Text"), "Please select an Employee", htmlAttributes: new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.EmployeeID, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.StartDate, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.StartDate, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.StartDate, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.EndDate, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.EndDate, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.EndDate, "", new { #class = "text-danger" })
</div>
</div>
And the jQuery:
$(function () {
$("#CompanyID").change(function () {
$("#EmployeeID").empty();
var token = $('[name=__RequestVerificationToken]').val();
$.getJSON('#Url.Action("GetEmployees")', { id: $(this).val() }, function (employees) {
var employeesSelect = $("#EmployeeID");
$.each(employees, function (i, employee) {
employeesSelect.append($('<option/>', {
value: employee.value,
text: employee.text
}));
});
});
});
});
Any suggestions would be greatly appreciated!
Return a collection of anonymous objects containing just the properties you need (no point sending a whole lot of data to the client that you don't even use)
employees.AddRange(employeeList);
var data = employees.Select(e => new
{
value = e.EmployeeID,
text = e.Name
};
return Json(data, JsonRequestBehavior.AllowGet);
Related
This is the class:
public class Book
{
public int id { get; set; }
public string BookName { get; set; }
public int AuthorId { get; set; }
public string AuthorFirstName { get; set; }
public string AuthorLastName { get; set; }
public List<Author> Authors_List { get; set; }
}
CSHTML:
<div class="form-group">
#Html.LabelFor(model => model.AuthorId, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.AuthorId, new { htmlAttributes = new { #class = "form-control" } })
#*#Html.DropDownList("AuthorId", null, htmlAttributes: new { #class = "form-contol"})*#
#Html.ValidationMessageFor(model => model.AuthorId, "", new { #class = "text-danger" })
</div>
</div>
I just don't understand how to return the authorList as a dropdown
I have created a viewmodel like this:
public class M_Master
{
public string SUPWH { get; set; }
public string STKGL { get; set; }
public string SALGL { get; set; }
public string COSGL { get; set; }
public decimal ROQ { get; set; }
public int MIN { get; set; }
public int MAX { get; set; }
public int LT { get; set; }
public string PRODSPEC { get; set; }
public string REMK1 { get; set; }
public string REMK2 { get; set; }
public decimal openingQty { get; set; }
public decimal openingAmt { get; set; }
public decimal onHandQty { get; set; }
public decimal ytdReceiptQty { get; set; }
}
Then I use this ViewModel to create a View. So the view looks something like the below:
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>INV_Master</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(model => model.PROD, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.PROD, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.PROD, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.WH, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.WH, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.WH, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.DESCR, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.DESCR, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.DESCR, "", new { #class = "text-danger" })
</div>
</div>
What I realise is that when I visit the page/view, the html inputfields by default are filled in with values like 0 for those properties in the ViewMoel which are int, decimal, datetime. How do I make sure that all the input fields by default are empty ?
Use Nullable types like int?, decimal?, and DateTime?. When objects are instantiated, each property will be initialized to the datatype default. Int defaults to 0, and int? defaults to null. And so on. You can still put a [Required] on the property to ensure they are entered by the user before being posted back to the server.
I've recently started with ASP.NET and I must say that I like it a lot. But in every relationship, you must hit some obstacle here and there. Here is mine:
My starting project includes creating simple schools system for managing students. I have several tables (Students, StudentAddresses, Grades, and Courses).
Here are problematic two tables:
1) Student table:
public Student()
{
this.Courses = new HashSet<Course>();
}
public int StudentId { get; set; }
[Required]
[StringLength(50, MinimumLength = 2, ErrorMessage = "The name must have over 2 and under 50 characters!")] // stavlja ograničenje na duljinu stringa u bazi
public string Name { get; set; }
[Required]
[StringLength(50, MinimumLength = 2, ErrorMessage = "The name must have over 2 and under 50 characters!")]
public string Surname { get; set; }
public int CurrentGradeId { get; set; }
public Grade CurrentGrade { get; set; }
public virtual StudentAdress Address { get; set; }
public virtual ICollection<Course> Courses { get; set; }
2) StudentAddress table:
public int StudentId { get; set; }
public string Address1 { get; set; }
public string Adress2 { get; set; }
public string City { get; set; }
public int ZipCode { get; set; }
public string Country { get; set; }
public virtual Student Student { get; set; }
In short, I'm trying to update StudentAddresses properties (to be more precise Address1 property for Student) while inside Student edit Action Method.
Here is View for Edit student:
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Student</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
#Html.HiddenFor(model => model.StudentId)
<div class="form-group">
#Html.LabelFor(model => model.Name, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Name, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Name, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Surname, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Surname, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Surname, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CurrentGradeId, "CurrentGradeId", htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.DropDownList("CurrentGradeId", null, htmlAttributes: new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.CurrentGradeId, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Address.Address1, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Address.Address1, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Address.Address1, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
And finally here is Edit Action Method for StudentsController:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "StudentId,Name,Surname,CurrentGradeId")] Student student )
{
if (ModelState.IsValid)
{
// getting student id for current studentid
StudentAdress addresa = db.Addresses.Find(student.StudentId);
// trying to bind input value
addresa.Address1 = student.Address.Address1.ToString();
// saving new value in StudentAddresses field Address1
db.Entry(addresa).State = EntityState.Modified;
db.SaveChanges();
db.Entry(student).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.CurrentGradeId = new SelectList(db.Grades, "GradeId", "GradeName", student.CurrentGradeId);
return View(student);
}
So, in Edit method, I want to save new input value for Address1 inside Edit method for Student table. Or to put it simpler, I want to update field Address1 in StudentAddress class while Editing Student class
UPDATE 1
So, let's say that I've figure it out but I'm still wondering if it is proper and right way of doing it.
In Student Edit action method I added addresa.Address1 = Request.Form["Address.Address1"]; where I updated field with attribute name=Address.Address1 and it did a trick but I'm wondering if it is right way of doing it?
Keep in mind that I've tried this
**addresa.Address1 = student.Address.Address1;**
but using this "cleaner" approach gave me:
System.NullReferenceException: Object reference not set to an instance
of an object.
Could I updated Address.Address1 field using some other approach?
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "StudentId,Name,Surname,CurrentGradeId")] Student student )
{
if (ModelState.IsValid)
{
StudentAdress addresa = db.Addresses.Find(student.StudentId);
// newly added line
addresa.Address1 = Request.Form["Address.Address1"];
db.Entry(addresa).State = EntityState.Modified;
db.SaveChanges();
db.Entry(student).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.CurrentGradeId = new SelectList(db.Grades, "GradeId", "GradeName", student.CurrentGradeId);
return View(student);
}
Your relationships are wrong.
In your StudentAddress model we can see the StudentId foreign key which means relationship between Student and StudentAddress is one to many. But in your Student model you have virtual StudentAdress Address which should be ICollection<StudentAdress> Addresses.
And in your add/edit you could just do:
var student = context.Student.Find(1);
student.Addresses.Add(new StudentAdress {
Address1 = "Ul. Janka Leskovara",
City = "Pregrada",
ZipCode = 49218,
Country = "Hrvatska"
});
context.SaveChanges();
I have two entities Gabarit and Local_Gabarit and i have a foreign key that related those entities called CodeBarre which is the primary Key of Gabarit. So on my Gabarit Edit Page i don't want to edit Gabarit attributes but the related attributes existing in Local_Gabarit such as Armoire and Emplacement.
Please, I need your help and Thank you :)
Gabarit Model:
public Gabarit()
{
this.Demande = new HashSet<Demande>();
this.Local_Gabarit = new HashSet<Local_Gabarit>();
this.Mvt_Gabarit = new HashSet<Mvt_Gabarit>();
}
public int CodeBarre { get; set; }
public string Designation { get; set; }
public string Photo { get; set; }
public string Exemplaire { get; set; }
public Nullable<int> Produit { get; set; }
public Nullable<int> Poste { get; set; }
public virtual ICollection<Demande> Demande { get; set; }
public virtual ICollection<Local_Gabarit> Local_Gabarit { get; set; }
public virtual ICollection<Mvt_Gabarit> Mvt_Gabarit { get; set; }
Local_Gabarit Model:
public partial class Local_Gabarit
{
public int id_local { get; set; }
public Nullable<int> Emplacement { get; set; }
public string Armoire { get; set; }
public int CodeBarre { get; set; }
public int id_demande { get; set; }
public string InOut { get; set; }
public virtual Demande Demande { get; set; }
public virtual Gabarit Gabarit { get; set; }
}
GabaritViewModel:
public class GabaritViewModel
{
public int CodeBarre { get; set; }
public string Designation { get; set; }
public string Photo { get; set; }
public Nullable<int> Produit { get; set; }
public string Exemplaire { get; set; }
public Nullable<int> Poste { get; set; }
public int id_local { get; set; }
public Nullable<int> Emplacement { get; set; }
public string Armoire { get; set; }
}
GabaritsController:
// GET: Gabarits/Edit/5
public ActionResult Edit(int? id)
{
var localrepository = new LocalGabaritRepository(db);
var dbgabarit = gabaritrepository.GetById(id);
var req = localrepository.Get(p => p.CodeBarre == dbgabarit.CodeBarre).SingleOrDefault();
var armoire = req.Armoire;
var emplacement = req.Emplacement;
if (dbgabarit != null)
{
var gabarit = new GabaritViewModel()
{
CodeBarre = dbgabarit.CodeBarre,
Designation = dbgabarit.Designation,
Photo = dbgabarit.Photo,
Exemplaire = dbgabarit.Exemplaire,
Poste=dbgabarit.Poste,
Produit=dbgabarit.Produit,
Emplacement=emplacement,
Armoire=armoire,
};
return View(gabarit);
}
else
return HttpNotFound();
}
// POST: Gabarits/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit( GabaritViewModel gabarit)
{
var localrepository = new LocalGabaritRepository(db);
if (ModelState.IsValid)
{
var req= localrepository.Get(p => p.CodeBarre == gabarit.CodeBarre).SingleOrDefault();
var armoire = req.Armoire;
var emplacement = req.Emplacement;
var idl = req.id_local;
var idd = req.id_demande;
var InOut = req.InOut;
var CodeBarre = req.CodeBarre;
var dblocal = new Local_Gabarit()
{
Emplacement = emplacement,
Armoire = armoire,
id_local=idl,
id_demande=idd,
InOut=InOut,
CodeBarre=CodeBarre
};
localrepository.Update(dblocal);
}
return View(gabarit);
}
Edit.cshtml (Gabarit):
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Gabarit</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
#Html.HiddenFor(model => model.CodeBarre)
<div class="form-group">
#Html.LabelFor(model => model.CodeBarre, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.CodeBarre, new { htmlAttributes = new { #class = "form-control", #readonly = "readonly" } })
#Html.ValidationMessageFor(model => model.CodeBarre, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group" >
#Html.LabelFor(model => model.Designation, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Designation, new { htmlAttributes = new { #class = "form-control", #readonly = "readonly" } })
#Html.ValidationMessageFor(model => model.Designation, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Photo, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
<img src="#Url.Content(Model.Photo)" width="200" height="200" />
#Html.ValidationMessageFor(model => model.Photo, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Produit, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Produit, new { htmlAttributes = new { #class = "form-control", #readonly = "readonly" } })
#Html.ValidationMessageFor(model => model.Produit, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Armoire, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Armoire, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Armoire, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Emplacement, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Emplacement, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Emplacement, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
I don't know if i'm in the right way or not but this is what i tried to do.
Thank you.
I have a page with 2 textboxes and 2 dropdown lists.
The dropdown lists have optionLabels on them and I want the required validation to show if these are selected.
One of the textboxes and both of the dropdown lists are 'Required'.
If I complete the required textbox and submit the form, the 'Required' validation on the dropdown lists doesn't fire, it only fires if the 'Required' textbox doesn't have a value.
MODELS
public class CreateCaseModel
{
public CaseRegModel CaseDetails { get; set; }
public List<StartTypeListModel> CaseStartTypeList { get; set; }
public List<ClientListModel> ClientsList { get; set; }
}
public class CaseRegModel
{
[Key]
public int CaseId { get; set; }
[Required]
[Display(Name = "PX Request Date")]
public DateTime PxRequestDate { get; set; }
[Required]
public int ClientId { get; set; }
[Required]
[Display(Name = "Start Type")]
public string StartType { get; set; }
[Display(Name = "List Price")]
public string ListPrice { get; set; }
}
public class ClientListModel
{
[Required]
public int ClientId { get; set; }
[Display(Name = "Client Name")]
public string ClientName { get; set; }
}
public class StartTypeListModel
{
public int Id { get; set; }
[Required]
[Display(Name = "Start Type")]
public string StartType { get; set; }
}
VIEW - CreateCaseModel
<div class="form-group">
#Html.LabelFor(model => model.CaseDetails.StartType, new { #class = "control-label col-md-4" })
<div class="col-md-6">
#*#Html.DropDownList("StartType", null, "Select Start Type...", new { #class = "form-control" })*#
#Html.DropDownListFor(model => model.CaseDetails.StartType, new SelectList(Model.CaseStartTypeList, "StartType", "StartType"), "Select Start Type...", new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.CaseDetails.StartType, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CaseDetails.PxRequestDate, htmlAttributes: new { #class = "control-label col-md-4" })
<div class="col-md-6">
#Html.EditorFor(model => model.CaseDetails.PxRequestDate, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CaseDetails.PxRequestDate, "", new { #class = "text-danger" })
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
#Html.LabelFor(model => model.CaseDetails.ClientId, new { #class = "control-label col-md-4" })
<div class="col-md-6">
#*#Html.DropDownList("ClientId", null, "Select Client...", new { #class = "form-control" })*#
#Html.DropDownListFor(model => model.CaseDetails.ClientId, new SelectList(Model.ClientsList, "ClientId", "ClientName"), "Select Client...", new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.CaseDetails.ClientId, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CaseDetails.ListPrice, htmlAttributes: new { #class = "control-label col-md-4" })
<div class="col-md-6">
#Html.EditorFor(model => model.CaseDetails.ListPrice, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CaseDetails.ListPrice, "", new { #class = "text-danger" })
</div>
</div>
CONTROLLER
// GET: Case/Create
public ActionResult Index()
{
//start type list
//var CategoryList = new List<string>();
var qStartTypes = (from st in efContext.CaseStartTypes
orderby st.Id
select new StartTypeListModel
{
Id = st.Id,
StartType = st.StartType
}).ToList();
//client list
//var CategoryList = new List<string>();
var qClients = (from c in efContext.PgsClients
orderby c.ClientName
select new ClientListModel
{
ClientId = c.ClientId,
ClientName = c.ClientName
}).ToList();
return View(new CreateCaseModel
{
CaseDetails = new CaseRegModel(),
CaseStartTypeList = qStartTypes,
ClientsList = qClients
});
}
Thanks for any help.