I am storing a name and address in session in a static session class. When a customer pulls up the payment screen, I prefill the form with the name and address. If customer A pulls up the credit card screen and then customer B pulls up the same screen, customer B has the name and address of customer A.
I'm thinking this is happening due to a 'static' session class? If this is the case, how do I avoid this?
Here is my MySession class:
public static class MySession
{
public static string BranchNumber { set; get; }
public static string AccountNumber { set; get; }
public static string Name { set; get; }
public static string CustomerEmail { get; set; }
public static string Street { get; set; }
public static string Zip { get; set; }
public static string Zip4 { get; set; }
}
And my form:
#model SssMobileIInquiry.Models.HomeModels.CreditCard
#{
ViewBag.Title = "Credit Card Payment";
}
<div class="container">
#using (Html.BeginForm("SubmitCreditCardCharge", "Home", FormMethod.Post))
{
<h4>Credit Card Payment</h4>
<div class="row">
<div class="col-sm-3">
Name
</div>
<div class="col-sm-9 focus">
#Html.TextBoxFor(m => m.NameOnCard, new { #class = "form-control" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
Street
</div>
<div class="col-sm-9">
#Html.TextBoxFor(m => m.Street, new { #class = "form-control" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
Zip Code
</div>
<div class="col-sm-9">
#Html.TextBoxFor(m => m.ZipCode, new { #class = "form-control", #maxlength = "9" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
Card Number
</div>
<div class="col-sm-9">
#Html.TextBoxFor(m => m.CardNumber, new { #class = "form-control" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
Expiration Date
</div>
<div class="col-sm-9 datefieldsmall">
#Html.TextBoxFor(m => m.ExpirationDateMonth, new { #class = "form-control", #maxlength = "2", #placeholder = "MM" })
</div>
<div class="col-sm-9 datefieldsmall">
#Html.TextBoxFor(m => m.ExpirationDateYear, new { #class = "form-control", #maxlength = "2", #placeholder = "YY" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
CVV Number
</div>
<div class="col-sm-9">
#Html.TextBoxFor(m => m.PinNumber, new { #class = "form-control", #maxlength = "4" })
</div>
</div>
<div class="row">
<div class="col-sm-3">
Amount
</div>
<div class="col-sm-9">
#Html.TextBoxFor(m => m.PaymentAmount, new { #class = "form-control", #maxlength = "7" })
</div>
</div>
<div class="warning">
#Html.ValidationMessageFor(m => m.PaymentAmount)
</div>
<div class="row">
<input id="submitpayment" class="btn btn-primary btn-block buttonx accountinfobutton" type="submit" value="Submit" />
</div>
}
#using (Html.BeginForm("AccountInfo", "Home", FormMethod.Post))
{
<div class="row">
<input id="submitpayment" class="btn btn-primary btn-block buttonx accountinfobutton" type="submit" value="Account" />
</div>
}
</div>
And my ActionResults:
public ActionResult CreditCard()
{
if (MySession.CorporationId == Guid.Empty || string.IsNullOrEmpty(MySession.AccountNumber))
{
return View("Index");
}
var model = new Models.HomeModels.CreditCard();
model.NameOnCard = MySession.Name;
model.Street = MySession.Street;
model.ZipCode = MySession.Zip;
model.PaymentAmount = MySession.TotalBalance.Contains("-") ? "" : MySession.TotalBalance;
if (MySession.BudgetBalance.GetNumericValue() > 0 && MySession.BudgetRate.GetNumericValue() > 0)
{
model.PaymentAmount = MySession.BudgetBalance;
}
return View("CreditCard", model);
}
I am populating my model with MySession:
model.NameOnCard = MySession.Name;
model.Street = MySession.Street;
model.ZipCode = MySession.Zip;
I'm not sure why the customer information is being displayed for another account logged in. Any ideas would be greatly appreciated.
Thanks for the help!
You're using static. Static means there is only 1 copy of the class and is shared throughout the application. You need to change it so it isn't static and you must instantiate this for each user.
Related
This is my view.
I'm starting with MVC C#.
Sorry if this is an a very easy question.
I'm trying to get a CheckBox value from the view. The idea is put some checkboxes on the view, convert these values to Int32, to concatenate on a string entity for afterlly save in my DB.
The checkboxes should not be linked to the model.
Could someone explain me how to do it and how to link the checkbox to the controller? I'm very confused.
This is my model.
namespace Crossdock.Models{
public class Roles
{
[Key]
[Column(Order = 0)]
public int RolID { get; set; }
[Display(Name = "Tipo de Usuario")]
public string Descripcion { get; set; }
[Display(Name = "Permisos")]
public string Permisos { get;set;}
//Permisos a validar por Área
//Guías
public bool GeneracionGuias { get; set; }
//CEDIS
public bool RecepcionPaquetes { get; set; }
public bool CrossdockTemporal { get; set; }
//Administración
public bool Catalogos { get; set; }
}
}
This is my controller code. Here is where i need parse the bool values from the model to int/string and concatenate for save on "Descripcion" string field.
// GET: Roles/Create
public ActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Roles cl)
{
if (!ModelState.IsValid)
{
return RedirectToAction("Index");
}
var rl = new Roles
{
RolID = 0,
Descripcion=cl.Descripcion,
Permisos=cl.Permisos,
};
objRol.Alta_Roles(rl);
return RedirectToAction("Index", new { area = "" });
}
This is my Create View.
#model Crossdock.Models.Roles
#{
ViewBag.Title = "Create";
}
<hr />
<h1>Registrar Nuevo Perfil de Permisos</h1>
<hr />
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(model => model.Descripcion, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Descripcion, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Descripcion, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Permisos, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Permisos, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Permisos, "", new { #class = "text-danger" })
</div>
</div>
<br />
<div class="container">
<div class="row justify-content-center">
<div class="col-4">
<h3>
Guías
</h3>
<span> | Generación de Guías: </span> #Html.CheckBoxFor(m => m.GeneracionGuias, true)
</div>
<div class="col-4">
<h3>
CEDIS
</h3>
<span> | Recepción de Paquetes: </span> #Html.CheckBoxFor(m => m.RecepcionPaquetes, false)
<br />
<span> | Crossdock Temporal: </span> #Html.CheckBoxFor(m => m.CrossdockTemporal, false)
</div>
<div class="col-4">
<h3>
Administración
</h3>
<span> | Catálogos: </span> #Html.CheckBoxFor(m => m.Catalogos, false)
</div>
</div>
</div>
<hr />
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Registrar" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
<br />
#Html.ActionLink("Regresar", "Index")
</div>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
I'm having a hard time posting back my Model to the controller. With what I have done, I only get the root element and one child posted back to the controller. I know the problem is that, with a recursive function, all the html elements end up having the same name, but how can I fix it? Since I don't know how many levels my list will have, I can't use for loops :/
This is my class:
public class BilletesViewModel
{
public string Id { get; set; }
public string IdPadre { get; set; }
public string IdHijo { get; set; }
public int Nivel { get; set; }
public string Familia { get; set; }
public string Material { get; set; }
public decimal Cantidad { get; set; }
public string UnidadDeMedida { get; set; }
public int UnidadDeMedidaId { get; set; }
public string Merma { get; set; }
public bool Raiz { get; set; }
public List<BilletesViewModel> ListaMateriales { get; set; }
public List<SelectListItem> ListaUnidadesDeMedida { get; set; }
}
And this is my view. I'm posting the whole thing in case I'm missing something else.
#model DulcesDeLaRosa.Models.BilletesViewModel
#{
ViewBag.Title = "Nuevo Billete de Materiales";
var disabled = Model.ListaMateriales != null && Model.ListaMateriales.Count > 0 ? "disabled" : "";
}
#helper ShowTree(List<DulcesDeLaRosa.Models.BilletesViewModel> ListaMateriales, int nivel, int contador)
{
if (ListaMateriales != null)
{
foreach (var material in ListaMateriales)
{
var marginLeft = 30 * nivel;
var marginString = marginLeft + "px;";
var claseBorde = nivel > 0 ? "" : "";
<div class="form-inline col-12" style="margin-top:2%">
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
#Html.HiddenFor(model => material.Id)
<hr />
<div class="col-4 delarosa-max-width">
<div class="form-group col-12 delarosa-max-width" style="margin-left:#marginString">
#Html.EditorFor(model => material.Material, new { htmlAttributes = new { #class = "form-control delarosa-max-width" } })
#Html.ValidationMessageFor(model => material.Material, "", new { #class = "text-danger" })
</div>
</div>
<div class="col-2">
<div class="form-group col-12 delarosa-max-width">
#Html.EditorFor(model => material.Cantidad, new { htmlAttributes = new { #class = "form-control delarosa-max-width" } })
#Html.ValidationMessageFor(model => material.Cantidad, "", new { #class = "text-danger" })
</div>
</div>
<div class="col-2">
<div class="form-group col-12 delarosa-max-width">
#Html.DropDownListFor(model => material.UnidadDeMedidaId, material.ListaUnidadesDeMedida, new { #class = "form-control delarosa-max-width" })
#Html.ValidationMessageFor(model => material.UnidadDeMedidaId, "", new { #class = "text-danger" })
</div>
</div>
<div class="col-2">
<div class="form-group col-12 delarosa-max-width">
#Html.EditorFor(model => material.Merma, new { htmlAttributes = new { #class = "form-control delarosa-max-width" } })
#Html.ValidationMessageFor(model => material.Merma, "", new { #class = "text-danger" })
</div>
</div>
<div class="col-2">
<div class="form-group col-12">
<div class="col-9 offset-1">
<button type="submit" id="BtnAgregar" name="btn" class="btn btn-info delarosa-background" value="Agregar|#material.Id">Agregar Hijo</button>
</div>
<div class="col-2">
<button type="submit" id="BtnEliminar" name="btn" class="btn btn-info delarosa-background" value="Eliminar|#material.Id">X</button>
</div>
</div>
</div>
</div>
if (material.ListaMateriales != null && material.ListaMateriales.Any())
{
<ul>
#ShowTree(material.ListaMateriales, nivel + 1, contador + 1)
</ul>
}
contador++;
}
}
}
<div style="margin-top: 20px;">
<h3>Nuevo Billete de Materiales</h3>
</div>
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-inline col-12 delarosa-margen-div delarosa-max-width">
<div class="form-inline col-12 delarosa-max-width">
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-inline col-11">
<div class="col-1">
<label class="delarosa-alineacion-izquierda">Familia: </label>
</div>
#Html.EditorFor(model => model.Familia, new { htmlAttributes = new { #class = "form-control", #id = "InputFamilia" } })
#Html.ValidationMessageFor(model => model.Familia, "", new { #class = "text-danger" })
#Html.HiddenFor(model => model.Raiz, new { #Value = Model.Raiz })
</div>
<div class="col-1">
<input type="submit" id="BtnAgregarRaiz" name="btn" class="btn btn-info delarosa-background" value="Agregar Raiz" #disabled />
</div>
</div>
</div>
if (!Model.Raiz)
{
<div class="form-inline col-12 delarosa-margen-div">
<div class="col-4">
<div class="form-group col-12 delarosa-alineacion-centro">
<label class="delarosa-alineacion-centro">Material</label>
</div>
</div>
<div class="col-2">
<div class="form-group col-12 delarosa-alineacion-centro">
<label class="delarosa-alineacion-centro">Cantidad</label>
</div>
</div>
<div class="col-2">
<div class="form-group col-12 delarosa-alineacion-centro">
<label class="delarosa-alineacion-centro">Unidad</label>
</div>
</div>
<div class="col-2">
<div class="form-group col-12 delarosa-alineacion-centro">
<label class="delarosa-alineacion-centro">Merma %</label>
</div>
</div>
<div class="col-2">
<div class="form-group col-12 delarosa-alineacion-centro">
<label class="delarosa-alineacion-centro">Acciones</label>
</div>
</div>
</div>
<hr style="margin-bottom:2%" />
#ShowTree(Model.ListaMateriales, 0, 0)
}
<div class="form-inline col-12 delarosa-margen-div" style="width:100%">
<div class="col-6" style="text-align:left;">
#Html.ActionLink("Regresar", "Index", null, new { #class = "btn btn-outline-danger" })
</div>
<div class="col-6" style="text-align:right;">
<input type="submit" name="btn" value="Crear" class="btn btn-outline-danger" />
</div>
</div>
}
Has anyone tried something similar? Is there any way I can solve this?
I'd appreciate any pointers
I have two model classes for my project,
public class BookModel
{
public Int64 ISBN { get; set; }
public DateTime AddedDate { get; set; }
public bool isActive { get; set; }
public int Quantity { get; set; }
public int? FormatID { get; set; }
public virtual FormatModel Format { get; set; }
}
and
public class FormatModel
{
public FormatModel()
{
Books = new HashSet<BookModel>();
}
public int ID { get; set; }
public string Value { get; set; }
public virtual ICollection<BookModel> Books { get; }
}
I want to create a modal in my Create.cshtml file to add a new format if the specified format doesn't exist.
How can I create a Submit button for my modal to add the format in FormatModel?
This is my view:
#model RookBookMVC.Models.BookModel
#{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.ReturnUrl = "/Book/Create";
}
<h2>Create</h2>
#using (Html.BeginForm("Create", "Book", FormMethod.Post))
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>BookModel</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(model => model.FormatID, "FormatID", htmlAttributes: new { #class = "control-label col-md-2" })
<div class="input-group col-md-10">
#Html.DropDownList("FormatID", null, "Select Book Format", htmlAttributes: new { #class = "form-control" })
<div class="input-group-append">
<button type="button" class="btn btn-secondary" data-toggle="modal" data-target="#exampleModalCenter">
Add New
</button>
</div>
</div>
#Html.ValidationMessageFor(model => model.FormatID, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.ISBN, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.ISBN, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.ISBN, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Quantity, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Quantity, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Quantity, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
#using (Html.BeginForm("Create", "Format", FormMethod.Post))
{
#Html.AntiForgeryToken()
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Add New Format</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
#Html.LabelFor(model => model.Format.Value, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Format.Value, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Format.Value, "", new { #class = "text-danger" })
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<input type="submit" value="Create Format" class="btn btn-default" />
</div>
</div>
</div>
</div>
}
<div>
#Html.ActionLink("Back to List", "Index")
</div>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
after I click on the 'Create Format' button. it returns false for ModelState.IsValid and doesn't add any data to my database
What should I do for making 'Create Format' Button make a new Entity for Format and save it in my database?
for Additional I need to create two models via a single page
You might have to create a View Model and pass the view model property as parameter to the Action - Format/ Create post.
ViewModel property:
public string FormatValue { get; set; }
Modal view:
#Html.EditorFor(model => model.FormatValue, new { htmlAttributes = new { #class = "form-control" } })
Controller code with parameter as the same name as the view model property being passed from the modal form:
[HttpPost]
public ActionResult Create(string formatValue)
{
using (var dataContext = new YourDbContextModel())
{
FormatModel fmtModel = new FormatModel();
fmtModel.Value = formatValue;
// rest of your code to save data
}
}
public class MYViewModel{ public string FormatValue { get; set; } }
Create.cshtml
#model MYViewModel
<div>
#Html.EditorFor(model => model.FormatValue, new { htmlAttributes = new { #class = "form-control" } })
</div>
Do You Mean something Like that?
OR
public class MYViewModel{
public string FormatValue { get; set; }
Public BookModel Book {get; set;}
}
I have Property Types and sub types that are stored in db, and i want to display these types and sub type in radiobutton.
I m sharing some details.
DB Tables Image
Here is ModelVM class
public class PropertyVM
{
//property table
public int property_id { get; set; }
public string property_purpose { get; set; }
public string property_sub_purpose { get; set; }
public string address { get; set; }
public string property_title { get; set; }
public string property_description { get; set; }
public Nullable<double> property_price { get; set; }
public Nullable<double> property_budget { get; set; }
public string property_land_area { get; set; }
public string bedroom { get; set; }
public string bathroom { get; set; }
public Nullable<int> property_status { get; set; }
public Nullable<System.DateTime> property_add_dateTime { get; set; }
public string property_ad_expiry { get; set; }
// property Type table
public int property_type_id { get; set; }
public string property_type_name { get; set; }
public Nullable<int> property_type_status { get; set; }
// property sub type table
public int property_sub_type_id { get; set; }
public string property_sub_type_name { get; set; }
public Nullable<int> property_sub_type_status { get; set; }
// for list of data
public string Selected_pt_list { get; set; }
public List<property_type> pt_list { get; set; }
public string Selected_pst_list { get; set; }
public List<property_sub_type> pst_list { get; set; }
}
Here is Controller Method
[HttpGet]
public ActionResult AddProperty()
{
PropertyVM obj = new PropertyVM();
obj.pt_list = db.property_type.Where(pt => pt.property_type_status == 1).ToList();
obj.pst_list = db.property_sub_type.Where(pst => pst.property_sub_type_status == 1).ToList();
return View(obj);
}
Here is UI Images
WHen Select 1st ProertyType(Radiobutton) it shows all its child subTYpes
WHen Select 2nd ProertyType(Radiobutton) it shows all its child subTYpes
WHen Select 3rd ProertyType(Radiobutton) it shows all its child subTYpes
NOTE : ALL PROPERTY TYPES AND SUB TYPES IN RADIO BUTTON, NOT CHECKBOX
Solve this issue by using Partialview Approach and Jquery and ajax.
Here is Solution
PartialView Property_Sub_Type
#model projectName.Areas.Dashboard.Models.ViewModels.PropertyVM
#foreach (var _pst in Model.pst_list)
{
//string divMainId = "propertyType" + _pst.property_type.property_type_name.Replace(" ", "") + "IfSelect";
string forLblSub = "radioPropertyType" + _pst.property_sub_type_name.Replace(" ", ""); // for label and its must use
forLblSub = forLblSub + _pst.property_sub_type_name.Replace(" ", ""); // for label and its must use
<div class="funkyradio">
<div class="funkyradio-info">
#Html.RadioButtonFor(ms => ms.Selected_pst_list, _pst.property_sub_type_id, new { #Name = "radioPropertyType" + _pst.property_sub_type_name.Replace(" ", "") + "Sub", id = "radioPropertyType" + _pst.property_type.property_type_name.Replace(" ", "") + _pst.property_sub_type_name.Replace(" ", "") })
<label for="#forLblSub">#_pst.property_sub_type_name</label>
</div>
</div>
}
Here is Main View Add_Property
#model ProjectName.Areas.Dashboard.Models.ViewModels.PropertyVM
#{
ViewBag.Title = "Add Property";
}
<!-- /.col -->
<div class="col-md-9">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Add a Property</h3>
#*#Html.Partial("~/Areas/Admin/Views/Shared/_errorMsg.cshtml")*#
</div>
<!-- /.box-header -->
<!-- form start -->
#using (Html.BeginForm("AddProperty", "PropertyManagment", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="box-body">
<div class="row heading_addProperty_main">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<span class="heading_addProperty_span">Property Purpose & Category</span>
</div>
</div>
<div class="form-group col-lg-12 col-md-12 col-sm-12" style="padding-left:0px;padding-right:0px;">
<label for="LabelPurpose" class="text-uppercase">Purpose</label>
<div class="funkyradio">
<div class="funkyradio-info">
#Html.RadioButtonFor(m => m.property_purpose, "Sale", new { #Name = "radioPurpose", id = "radioPurposeSale" })
<label for="radioPurposeSale">For Sale</label>
</div>
<div class="funkyradio-info">
#Html.RadioButtonFor(m => m.property_purpose, "Rent", new { #Name = "radioPurpose", id = "radioPurposeRent" })
<label for="radioPurposeRent">Rent</label>
</div>
<div class="funkyradio-info">
#Html.RadioButtonFor(m => m.property_purpose, "Wanted", new { #Name = "radioPurpose", id = "radioPurposeWanted" })
<label for="radioPurposeWanted">Wanted</label>
</div>
</div>
</div>
<!-- Wanted Sub Radio -->
<div class="form-group col-lg-12 col-md-12 col-sm-12" style="padding-left:10px;padding-right:0px;" id="wantedIfSelect">
<label for="LabelWanted" class="text-uppercase">Wanted</label>
<div class="funkyradio">
<div class="funkyradio-info">
#Html.RadioButtonFor(m => m.property_purpose, "Buy", new { #Name = "radioWanted", id = "radioWantedBuy" })
<label for="radioWantedBuy">Buy</label>
</div>
<div class="funkyradio-info">
#Html.RadioButtonFor(m => m.property_purpose, "Rent", new { #Name = "radioWanted", id = "radioWantedRent" })
<label for="radioWantedRent">Rent</label>
</div>
</div>
</div>
<!-- Property Type Partial View -->
#{Html.RenderAction("_PropertyTypePartial", "PropertyManagment");}
<!-- Property Type Partial View -->
<div class="form-group col-lg-12 col-md-12 col-sm-12" style="padding-left:10px;padding-right:0px;" id="loadPartial">
</div>
#*#{Html.RenderAction("_PropertySubTypePartial", "PropertyManagment", new { id = Model.Selected_pt_list });}*#
<div class="row heading_addProperty_main">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<span class="heading_addProperty_span">Property Location</span>
</div>
</div>
<div class="form-group col-lg-6 col-md-6 col-sm-6" style="padding-left:0px;">
<label for="LabelCity" class="text-uppercase">City</label>
#Html.DropDownList("city_id", null, "Select One", htmlAttributes: new { #class = "form-control select2" })
#Html.ValidationMessageFor(model => model.city_id, "", new { #class = "text-danger" })
</div>
<div class="form-group col-lg-6 col-md-6 col-sm-6" style="padding-right:0px;">
<label for="LabelLocation" class="text-uppercase">Address</label>
#Html.EditorFor(model => model.address, new { htmlAttributes = new { #class = "form-control", #PlaceHolder = "Enter Complete Address" } })
#Html.ValidationMessageFor(model => model.address, "", new { #class = "text-danger" })
</div>
<div class="row heading_addProperty_main">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<span class="heading_addProperty_span">Property Details</span>
</div>
</div>
<div class="form-group col-lg-6 col-md-6 col-sm-6" style="padding-left:0px;">
<label for="LabelPropertyTitle" class="text-uppercase">Property Title</label>
#Html.EditorFor(model => model.property_title, new { htmlAttributes = new { #class = "form-control", #PlaceHolder = "Enter Title" } })
#Html.ValidationMessageFor(model => model.property_title, "", new { #class = "text-danger" })
</div>
<div class="form-group col-lg-6 col-md-6 col-sm-6" style="padding-right:0px;">
<label for="LabelPrice" class="text-uppercase">Final Price (PKR)</label>
#Html.EditorFor(model => model.property_price, new { htmlAttributes = new { #class = "form-control", #PlaceHolder = "Enter Price (All Inclusive)" } })
#Html.ValidationMessageFor(model => model.property_price, "", new { #class = "text-danger" })
</div>
<div class="form-group col-lg-6 col-md-6 col-sm-6" style="padding-left:0px;">
<label for="LabelLandArea" class="text-uppercase">Land Area</label>
#Html.EditorFor(model => model.property_land_area, new { htmlAttributes = new { #class = "form-control", #PlaceHolder = "Enter Land Area" } })
#Html.ValidationMessageFor(model => model.property_land_area, "", new { #class = "text-danger" })
</div>
<div class="form-group col-lg-6 col-md-6 col-sm-6" style="padding-right:0px;">
<label for="LabelAreaUnit" class="text-uppercase">Area Unit</label>
#Html.DropDownList("land_area_unit_id", null, "Select One", htmlAttributes: new { #class = "form-control select2" })
#Html.ValidationMessageFor(model => model.land_area_unit_id, "", new { #class = "text-danger" })
</div>
<div class="form-group col-lg-6 col-md-6 col-sm-6" style="padding-left:0px;">
<label for="LabelDescription" class="text-uppercase">Description</label>
#Html.TextAreaFor(model => model.property_description, new { #class = "form-control", #cols = 3, #rows = 3, #style = " resize: none;" })
</div>
<div class="form-group col-lg-6 col-md-6 col-sm-6" style="padding-right:0px;">
<label for="LabelExpiresAfter" class="text-uppercase">Expires After</label>
<input type="text" class="form-control" placeholder="">
</div>
<div class="row heading_addProperty_main">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<span class="heading_addProperty_span">Add Images</span>
</div>
</div>
<div class="form-group col-lg-12 col-md-12 col-sm-12" style="padding-right:0px;padding-left:0px;">
<div class="upload-btn-wrapper">
<button class="btn_upload"><i class="icon icon-bar"></i> Upload Images</button>
<input type="file" name="propertyImages" multiple />
<span class="label label-warning" style="padding:5px; font-size:12px;"><i class=""></i> Press CTRL key while selecting images to upload multiple images at once</span>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<input type="submit" class="btn btn-success btn-sm" value="Submit">
#Html.ActionLink("Back to List", "Index", "City", null, new { #class = "btn btn-primary btn-sm" })
</div>
}
</div>
</div>
<!-- /.col -->
Here is Jquery
// Load property sub type based on property type selection
$("input:radio[name='radioPropertyType']").change(function () {
// get selected radiobutton value
var id = $("input:radio[name='radioPropertyType']:checked").val();
// get div name where we display data
var divToLoad = $("#loadPartial");
// call controller method
$.ajax({
cache: false,
type: "GET",
url: "#(Url.Action("_PropertySubTypePartial", "PropertyManagment"))",
data: { "id": id },
success: function (data) {
divToLoad.html(' ');
divToLoad.html(data);
},
error: function (xhr, ajaxOptions, thrownError) {
divToLoad.html(' ');
}
});
});
The issue is that, model binding doesn't bind one of the properties of ViewModel.
I have a ViewMode, HomeIndexViewModel.
One of the properties, ExcludeClientsWithoutAddress doesn't get bound in controller.
Fiddler shows GET request as such (without ExcludeClientsWithoutAddress)
GET /Home/searchByClient?db=dev&fileNumber=&firstName=xxx&includeContacts=true HTTP/1.1
For some reason, Other properties (FileNumber, FirstName, LastName, IncludeContacts, and File) get bound correctly.
What am I missing here?
namespace CertifiedMail.Web.Mvc4.OneOffs.Models
{
public class HomeIndexViewModel
{
[DisplayName("File #")]
public string FileNumber { get; set; }
[DisplayName("First Name")]
public string FirstName { get; set; }
[DisplayName("Last Name")]
public string LastName { get; set; }
[DisplayName("Include Contact")]
public bool IncludeContacts { get; set; }
[DisplayName("Exclude Clients Without Address")]
public bool ExcludeClientsWithoutAddress { get; set; }
public HttpPostedFileBase File { get; set; }
}
}
Within Controller,
[System.Web.Mvc.HttpGet]
public string SearchByClient([FromUri]HomeIndexViewModel model)
{
IEnumerable<SearchResult> searchResults = new List<SearchResult>();
SearchByArgs args = BuildSearchByArg(model);
if (string.IsNullOrWhiteSpace(model.FileNumber))
{
if (!string.IsNullOrWhiteSpace(model.FirstName) || !string.IsNullOrWhiteSpace(model.LastName))
searchResults = ClientSearchDataAccess.SearchByClientName(args);
}
else
searchResults = ClientSearchDataAccess.SearchByClientNumber(args);
return JsonConverter.SerializeSearchResults(searchResults);
}
Here is the View.
<div class="col-sm-5 searchPanel">
<div class="panel panel-default glowGridPanel">
<div class="panel-body searchPanelBody">
<div class="row">
#using (Html.BeginForm("SearchByClient", "Home",
new { db = #Request.QueryString["db"] },
FormMethod.Get,
new { id = "searchByClientForm", #class = "form-horizontal" }))
{
<fieldset>
<legend>
Search by Client
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>
</legend>
#{
var labelAttributes = new { #class = "col-sm-4 control-label" };
}
<div class="form-group">
#Html.LabelFor(m => m.FileNumber, labelAttributes)
<div class="col-sm-8">
#Html.TextBoxFor(m => m.FileNumber, new { #class = "form-control input-sm", ng_model = "fileNumber" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.FirstName, labelAttributes)
<div class="col-sm-8">
#Html.TextBoxFor(m => m.FirstName, new { #class = "form-control input-sm", ng_model = "firstName" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.LastName, labelAttributes)
<div class="col-sm-8">
#Html.TextBoxFor(m => m.LastName, new { #class = "form-control input-sm", ng_model = "lastName" })
</div>
</div>
<div class="form-group">
<div class="col-sm-12 col-sm-offset-3">
<div class="checkbox">
Include contacts in search result?
#Html.CheckBoxFor(m => m.IncludeContacts, new { id = "includeContactsCheckBox", ng_model = "includeContacts" })
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12 col-sm-offset-3">
Exclude Clients without Address?
<div class="checkbox">
#Html.CheckBoxFor(m => m.ExcludeClientsWithoutAddress,
new { id = "excludeClientsWithoutAddressCheckBox", ng_model = "excludeClientsWithoutAddress" })
</div>
</div>
</div>
<button type="button" class="btn btn-primary pull-right submitButton"
ng-click="addSearchResultToGrid()"
ng-disabled="loadingSearch">
Search by Client
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
<div id="loadingSearch" ng-show="loadingSearch"></div>
</button>
</fieldset>
}
</div>
<div class="row strike">
<h3>
<span class="label label-default">
<span class="glyphicon glyphicon-minus" aria-hidden="true"></span>
OR
<span class="glyphicon glyphicon-minus" aria-hidden="true"></span>
</span>
</h3>
</div>
<div class="row">
#using (Html.BeginForm("Upload", "Home",
new { db = #Request.QueryString["db"] },
FormMethod.Post, new { id = "uploadFileForm", enctype = "multipart/form-data" }))
{
<fieldset>
<legend>Search by Uploading File</legend>
<div class="input-group">
<input type="file" class="form-control" name="file" id="file" />
<span class="input-group-btn">
<button class="btn btn-primary" type="submit">
Upload File
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>
</button>
</span>
</div>
</fieldset>
}
</div>
</div>
</div>
</div>
Your Fiddler request shows what is emitted from the browser. It isn't sending your ExcludeClientsWithoutAddress property.
Since this property is not marked nullable bool? it is being assigned a default value in binding.
You have these inputs as ng_model which suggests your Angular code is not sending this field.