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.
Related
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 am trying to submit a form that incorporates an #Html.EditorFor element. If I remove the EditorFor element, my POST controller argument passes data correctly, but once implemented, my entire model argument shows as null in the POST controller.
Here's the model I'm trying to pass:
public class Checkout
{
public int CheckoutID { get; set; }
public string Requestor { get; set; }
public DateTime? DateRequested { get; set; }
public List<CheckoutReceiver> Receivers { get; set; }
}
The form element on page:
#model PRI.Models.Checkout
#using (Html.BeginForm("CreateCheckout", "API/CheckoutRequest", FormMethod.Post, new { id = "pri-form" }))
{
<div id="checkout-request">
#Html.AntiForgeryToken()
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div id="checkout-info" class="form-horizontal">
<div class="form-group">
<div class="col-md-12">
#Html.TextBoxFor(m => m.CheckoutID)
</div>
</div>
<div class="form-group">
<div class="col-md-12">
#Html.EditorFor(m => m.Receivers)
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input id="create-checkout-submit" type="submit" value="Confirm transfer" class="btn btn-danger right" style="margin: 10px;" />
</div>
</div>
</div>
</div>
}
If I remove the #Html.EditorFor(m => m.Receivers), and add data to the #Html.TextBoxFor(m => m.CheckoutID) then that passes correctly to my Post Controller, so obviously my EditorFor is messing things up:
Here's the POST controller (i put a breakpoint right after it enters this so I can check the checkout argument):
[System.Web.Http.HttpPost]
[ValidateAntiForgeryToken]
[System.Web.Http.ActionName("CreateCheckout")]
public Checkout Create(Checkout checkout)
{
var request = new Checkout();
return request;
}
Here's my CheckoutReceiver Editor template (removed some input elements for brevity):
#model PRI.Models.CheckoutReceiver
#using (Html.BeginCollectionItem("Receivers"))
{
<div class="form-horizontal">
#Html.HiddenFor(model => model.ID)
#Html.HiddenFor(model => model.CheckoutID)
<h4 class="contact-header">#Model.ContactType</h4>
<div class="form-group">
<div class="col-md-5">
<span class="form-header">Last Name</span>
#Html.TextBoxFor(model => model.LastName, new { #class = "box-customer form-control ignore", placeholder = "Last name" })
</div>
<div class="col-md-5">
<span class="form-header">First Name</span>
#Html.TextBoxFor(model => model.FirstName, new { #class = "form-control ignore", placeholder = "First name" })
</div>
<div class="col-md-2">
<span class="form-header">Middle Initial</span>
#Html.TextBoxFor(model => model.MiddleInitial, new { #class = "form-control ignore", placeholder = "M.I." })
</div>
</div>
</div>
}
Where am I going wrong, and why is my EditorFor causing my Checkout POST argument to be null on submit?
Thanks!
Maybe you should check this question. You should add an editor for an
IEnumerable<CheckoutReceiver> instead of an editor for CheckoutReceiver.
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.
I'm going straight to the point here guys,
I have a form. when I save the form... it only gets the firstname, middlename and lastname.. it doesn't get the files... however, if I only get the photo and comment out other inputs... the photo is captured on my model.. I dunno why it behaves like this.. I'm really new to asp.net mvc.. so please bear with me..
#model Impulse.ViewModels.AgentViewModel
#{
ViewBag.Title = "AgentForm";
Layout = "~/Views/Shared/_SiteLayout.cshtml";
}
<div class="custom-container">
<h1 class="title"><strong>Add New Agent</strong></h1>
<hr />
#using (Html.BeginForm("Save", "Agent", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="row">
<div class="col-md-3">
<div id="preview">
<img src="~/Content/Assets/no-image.png" id="profile_image" class="img-thumbnail" />
</div>
<div class="form-group">
<label>Profile Picture</label>
<input type="file" name="photo" id="photo" />
</div>
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-4">
<div class="form-group">
#Html.LabelFor(m => m.Agent.FirstName)
#Html.TextBoxFor(m => m.Agent.FirstName, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Agent.FirstName)
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
#Html.LabelFor(m => m.Agent.MiddleName)
#Html.TextBoxFor(m => m.Agent.MiddleName, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Agent.MiddleName)
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
#Html.LabelFor(m => m.Agent.LastName)
#Html.TextBoxFor(m => m.Agent.LastName, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Agent.LastName)
</div>
</div>
</div>
</div>
</div>
<input type="submit" class="btn btn-primary" value="Save" />
}
</div>
Controller
[HttpPost]
public ActionResult Save(AgentModel agent)
{
//I debug here to see the data passed by my view
return Content("Sample");
}
Model
public class AgentModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleName { get; set; }
[FileSize(10240)]
[FileTypes("jpg,jpeg,png")]
public HttpPostedFileBase photo { get; set; }
}
you can try like this
Model
public class UploadFileModel
{
public UploadFileModel()
{
Files = new List<HttpPostedFileBase>();
}
public List<HttpPostedFileBase> Files { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleName { get; set; }
}
View
#using (Html.BeginForm("UploadData", "Home", FormMethod.Post, new { encType="multipart/form-data" }))
{
#Html.TextBoxFor(m => m.FirstName)
<br /><br />
#Html.TextBoxFor(m => m.Files, new { type = "file", name = "Files" })<br /><br />
<input type="submit" value="submit" name="submit" id="submit" />
}
Controller
public ActionResult UploadData(UploadFileModel model)
{
var file = model.Files[0];
return View(model);
}
you are binding to view to AgentViewModel so you will get AgentViewModel when you post server. so the parameter to action save should be viewmodel. Or Else change view to bind to AgentModel.
The file control that you have used is html input type. try using below code.
#Html.TextBoxFor(m => Model.File, new { type = "file" , accept=".pdf"})
#Html.ValidationMessageFor(m => Model.File)
So, I have an issue with a controller/view/viewmodel. It's similar to this issue I think. Basically, I have a viewmodel that I send to a view from my controller. There are items that display and then some additional fields for the user to manipulate before the whole mess is sent back over to a controller post action. When I get the data back in my post, all of the viewmodel is empty.
So, without further ado, here's some code to look at:
ViewModel:
public class ASideReceivingViewModel
{
public PurchaseOrderLine poLine;
public ReceivingItem receivingItem;
public Dictionary<string, string> TankerOrRailcarOptions { get; set; }
public ASideReceivingViewModel()
{
TankerOrRailcarOptions = new Dictionary<string, string>();
TankerOrRailcarOptions.Add("R", "Railcar");
TankerOrRailcarOptions.Add("T", "Tanker");
}
}
Controller Actions:
public ActionResult Receive(string strOrdNo, short? shtLineNo)
{
//if there isn't a selected po line, then shoot them back to the first page
if (strOrdNo == null || !shtLineNo.HasValue) return RedirectToAction("Index");
PurchaseOrderService poService = new PurchaseOrderService();
ReceivingItemService s = new ReceivingItemService(p);
ASideReceivingViewModel vm = new ASideReceivingViewModel();
vm.poLine = poService.GetOpenPurchaseOrderLines().Where(po => po.Ord_no == strOrdNo &&
po.Line_no == shtLineNo).FirstOrDefault();
if (vm.poLine == null) return RedirectToAction("Index");
vm.receivingItem = s.CreateNewReceivingItem(vm.poLine);
return View(vm);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Receive(ASideReceivingViewModel mytestvm)
{
if (ModelState.IsValid && mytestvm.receivingItem != null)
{
ReceivingItemService s = new ReceivingItemService(p);
s.Update(mytestvm.receivingItem);
return RedirectToAction("Index");
}
return View(mytestvm);
}
View:
#model FSIApps.Presentation.Models.ASideReceivingViewModel
<div class="row">
#{Html.RenderPartial("POLineDetails", Model.poLine);}
</div>
#using (Html.BeginForm("Receive", "Receiving", FormMethod.Post))
{
#Html.HiddenFor(model => model.receivingItem.Id)
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="row">
#Html.AntiForgeryToken()
<div class="col-md-6">
<div class="form-group">
<label for="receivingItem_Batch_number">Batch Number</label>
#Html.TextBoxFor(model => model.receivingItem.Batch_number, new { #class = "form-control" })
<span class="help-block">*Also the Vendor Lot Number on the BOL</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="receivingItem_Qty_received">Qty Received</label>
#Html.TextBoxFor(model => model.receivingItem.Qty_received, new { #class = "form-control" })
<span class="help-block">*Qty shown on BOL</span>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="receivingItem_Carrier">Carrier</label>
#Html.TextBoxFor(model => model.receivingItem.Carrier, new { #class = "form-control" })
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="receivingItem_">Tanker or Railcar</label>
#Html.DropDownListFor(m => m.receivingItem.Tanker_or_railcar, new SelectList(Model.TankerOrRailcarOptions, "Key", "Value", Model.receivingItem.Tanker_or_railcar), new { #class = "form-control" })
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="receivingItem_Railcar_number">Railcar Number</label>
#Html.TextBoxFor(model => model.receivingItem.Railcar_number, new { #class = "form-control" })
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="receivingItem_Manifest_number">Manifest Number</label>
#Html.TextBoxFor(model => model.receivingItem.Manifest_number, new { #class = "form-control" })
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="submit" value="Save" class="btn btn-success" />
</div>
</div>
</div>
</div>
</div>
}
I don't necessarily care about the data I send to the partial view, but when I post back the regular form I get nothing set in the ViewModel. In the other post they talk about how that's an issue with naming the parameter sent back to the controller, but no combination of setting the value in my #Html.BeginForm() seems to do the trick.
Anyone have any advice for me here?
Edited:
To use the automatic model binding, you should use properties instead of fields in the view model. Hopefully this does the trick:
public class ASideReceivingViewModel
{
public PurchaseOrderLine poLine { get; set; };
public ReceivingItem receivingItem { get; set; };
...
}