I am trying to find the best solution so that on any given page I always have a login model, a register model and another model (or more). The login and register models are found in the navbar and the footer respectively on each page.
Specifically I have a situation whereby I have a course page which populates from a table depending on which course has been looked up via the url inputted. So the page loads the course page model. On the same page in the header and footer I need to have the login and register forms which both require their own models.
The course page is populated using a foreach loop:
COURSE PAGE VIEW (SHORTENED):
#model IEnumerable<oltinternational_mvc.Models.Course_page>
#{
Layout = "~/Views/Shared/_courselayout.cshtml";
foreach (var cpage in Model) { ViewBag.Title = #cpage.page_title; }
}
#foreach (var cpage in Model)
{
if (cpage.template_type == 2)
{
<div id="main_container">
<article class="content">
<h1>
#cpage.Title
</h1>
<section>
#Html.Raw(cpage.main_image)
<h3>
#cpage.Country
</h3>
<p>#cpage.intro_1</p>
#if (!string.IsNullOrEmpty(cpage.intro_2))
{
<p>#cpage.intro_2</p>
}
#if (!string.IsNullOrEmpty(cpage.intro_3))
{
<p>#cpage.intro_3</p>
}
View sample pages
#if (!string.IsNullOrEmpty(cpage.website_button))
{
#Html.Raw(cpage.website_button)
}
else {
Licensing options
}
#Html.Raw(cpage.popup_script)
<div class="clearfloat"></div>
</section>
</article>
</div>
The controller is as follows:
public ActionResult Course_page(string id)
{
string abbrev = id;
var cpage = from c in db.Course_page
select c;
if (!String.IsNullOrEmpty(abbrev))
{
cpage = cpage.Where(x => x.abbrev.Contains(abbrev));
}
return View(cpage);
}
and the model:
[Table("course_page")]
public class Course_page
{
[Key]
public int CourseID { get; set; }
public string Meta { get; set; }
public string Title { get; set; }
public string Country { get; set; }
public string main_image { get; set; }
public string list_1 { get; set; }
public string list_2 { get; set; }
public string list_3 { get; set; }
public string list_4 { get; set; }
public string list_5 { get; set; }
public string list_6 { get; set; }
public string list_7 { get; set; }
public string list_8 { get; set; }
public string list_9 { get; set; }
public string list_10 { get; set; }
public string testim_1 { get; set; }
public string testim_2 { get; set; }
public string testim_3 { get; set; }
public string course_site { get; set; }
public string popup_script { get; set; }
public string abbrev { get; set; }
public string page_title { get; set; }
public int template_type { get; set; }
public string intro_1 { get; set; }
public string intro_2 { get; set; }
public string intro_3 { get; set; }
public string website_button { get; set; }
}
In the navbar I have the following list item which references my ajax logging in form:
<li class="login">
<span>Login</span>
#using (Ajax.BeginForm("login", "Account", new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "login_box"
}, new { id = "login_box" }))
{
#Html.Partial("_login")
}
</li>
Which loads this form:
#model myproject_mvc.Models.LoginViewModel
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<div id="login_box">
<div class="sign_up_box"> Sign up in seconds </div>
#Html.ValidationSummary(true)
#Html.AntiForgeryToken()
<div class="login_box_lower">
<p class="login_box_or">or</p>
<p class="login_sign_in">Sign in</p>
<div style="position:relative;">
#Html.EditorFor(model => model.Email, new { htmlAttributes = new { placeholder = "Email", maxlength = "18", #class = "login_username clearable" } })
<span class="login_username_icon"></span>
</div>
<div style="position:relative;">
#Html.EditorFor(model => model.Password, new { htmlAttributes = new { placeholder = "Password", maxlength = "18", #class = "login_pw clearable" } })
<span class="login_pw_icon"></span>
</div>
Login
<div class="clearfloat"></div>
Forgot password?
</div>
</div>
With the following model:
public class LoginViewModel
{
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
The same situation is such for the Register form in the footer, which uses the RegisterViewModel. Bearing in mind the actual form above for logging in isn't completed yet, it just directs to a /account url for now.
I've tried a few solutions I've found online but can't seem to make any of them work, I think in part because I am using foreach to populate the view from the course page model. I don't see how I can use a viewmodel because I am using a foreach loop on the page.
What I would like to know is what is the best way to deal with this situation?
You should create and use viewmodel(s) instead of directly referencing your objects. Perhaps something like this.
Create a new class, MyViewModel.cs (or whatever name you prefer)
public class MyViewModel
{
public IEnumerable<oltinternational_mvc.Models.Course_page> CoursePages { get; set; }
public myproject_mvc.Models.LoginViewModel { get; set; }
}
Now in your view, instead of referencing the models directly, you would reference the view model. Something like #model myproject_mvc.ViewModels.MyViewModel
In your foreach loop you would so something like this #foreach (var cpage in Model.CoursePages)
Related
I am new to programming, I am trying to create a shopping site like users sell their products.
I have products and a user's table. There is a "userId" column in the products table which is referenced by "ID" in the user's table. Only logged users can add product and I want to show products in each user's profile which they added. My code is below.
But here is the Error:Value cannot be null.Parameter name: source.
What is wrong with this code or is there any other way to do it.
My view:
<section class="page-section" id="relatedprod">
<div class="container">
<div class="row middle">
#foreach (Product prd in Model.Prod.Where(i=>i.userid==Model.userr.ID))
{
<div class="col-md-4">
<figure class="card card-product mehsul">
<div class="img-wrap"> <img class="img-fluid mehsulimg" src="~/PublicFront/images/30off6ec8.jpg" alt=""> </div>
<div class="handhover">
<img class="img-fluid" src="~/PublicFront/images/serv2b712.jpg" alt="">
</div>
<figcaption class="info-wrap">
<h4 class="title">#prd.ProdName</h4>
<p class="#prd.Price"></p>
</figcaption>
<div class="bottom-wrap">
Order Now
<div class="price-wrap h5">
<span class="price-new">$1280</span> <del class="price-old">$1980</del>
</div> <!-- price-wrap.// -->
</div> <!-- bottom-wrap.// -->
</figure>
</div> <!-- col // -->
}
</div>
</div>
</section>
Controller
public ActionResult MainAccount(int?id)
{
User us = Session["ActiveUser"] as User;
var vm = new HMViewM()
{
homesec1 = _context.homesec1slider.ToList(),
userr=us,
};
return View(vm);
}
namespace HandMShop.ViewModel
{
Models:
public class HMViewM
{
public List<homesec1slider> homesec1 { get; set; }
public User userr { get; set; }
public List<Category> catg { get;set; }
public List<Colour> colrs { get; set; }
public List<PhotoProduct> Photopr { get; set; }
public List<Product> Prod { get; set; }
}
}
public partial class Product
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Product()
{
this.PhotoProducts = new HashSet<PhotoProduct>();
}
public int id { get; set; }
public string ProdName { get; set; }
public string Price { get; set; }
public string Discount { get; set; }
public Nullable<int> CategoryId { get; set; }
public Nullable<int> AvailableID { get; set; }
public string Description { get; set; }
public string Material { get; set; }
public Nullable<byte> Enable { get; set; }
public Nullable<int> userid { get; set; }
public Nullable<System.DateTime> prodpostDate { get; set; }
public string ProdGenderId { get; set; }
public string sifarishle { get; set; }
public Nullable<int> LanguageId { get; set; }
public Nullable<int> colourId { get; set; }
public string Olcusu { get; set; }
public virtual AvailableTb AvailableTb { get; set; }
public virtual Category Category { get; set; }
public virtual Colour Colour { get; set; }
public virtual LanguageTb LanguageTb { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<PhotoProduct> PhotoProducts { get; set; }
public virtual User User { get; set; }
}
}
Oh okay, it seems that your product list property is empty, use the code below to fill it.
public ActionResult MainAccount(int?id)
{
User us = Session["ActiveUser"] as User;
// add Prod = _context.Product.Where(p=>p.User.ID == us.ID).ToList()
var vm = new HMViewM()
{
homesec1 = _context.homesec1slider.ToList(),
userr = us,
Prod = _context.Product.Where(p=>p.User.ID == us.ID).ToList()
};
return View(vm);
}
I'm trying to use a progress bar in my web application to visually display the number of signatures a cause (petition) has relative to the target number of signatures. Part of the Cause model is a list of Signatures existing in another table. I'm trying to create and add the current variables to the progress bar, but none of my attempts seem to be working and I'm unsure where I'm going wrong. I have tried several permutations of the following code without any success. I just get empty progress bars in the web browser. Any help would be appreciated:
#model IEnumerable<SoWokeWebApp.Models.Cause.Cause>
#{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
#foreach (var item in Model)
{
<div class="jumbotron">
<img src="#item.ImageURL" alt="Alternate Text" class="img-fluid" />
<h1>#Html.DisplayFor(model => item.CauseTitle)</h1>
<p>#Html.DisplayFor(model => item.Description)</p>
<p>#item.Signatures.Count</p>
#foreach (var Signature in item.Signatures)
{
<p>#Signature.UserEmail</p>
<p>#Signature.FirstName</p>
}
#{int target = item.TargetSignatures;
int current = item.Signatures.Count;
int progress = current / target * 100;}
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: #progress%" aria-valuenow="#current" aria-valuemin="0" aria-valuemax="#target"></div>
</div>
<p><a class="btn btn-primary btn-lg" href="#" role="button">#Html.ActionLink("Sign Cause", "Create", "Signatures")</a></p>
</div>
The models are as follows:
public class Cause
{
[Key]
[StringLength(100)]
[DisplayName("Cause Title")]
public string CauseTitle { get; set; }
[Required]
[StringLength(500)]
public string Description { get; set; }
[Required]
public string UserEmail { get; set; }
[Required]
[DisplayName("Date Posted")]
public DateTime DatePosted { get; set; }
public string ImageURL { get; set; }
[DisplayName("Catagory")]
public string CatagoryTitle { get; set; }
[ForeignKey("CatagoryTitle")]
public Catagory Catagory { get; set; }
[DisplayName("Signatures Target")]
public int TargetSignatures { get; set; }
public virtual List<Signature> Signatures { get; set; }
}
and
public class Signature
{
[Key]
public int SignatureId { get; set; }
[Required]
public string UserEmail { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
[Required]
public string CauseTitle { get; set; }
[ForeignKey("CauseTitle")]
public virtual Cause Cause { get; set; }
}
I found this neat little trick using SignalR with a Bootstrap Progress Bar in MVC:
SignalR Progress Bar Simple Example - Sending Live Data from Server to Client
I had to tweak ProgressHub.cs and change hubContext.Clients.All to hubContext.Clients.Group(user) or the progress bar messages went to all clients. See: Working with Groups in SignalR
It does seem to generate some traffic.
I'm creating new product belonging to the category model.When i execute my Create method, the error invoke that
"Object Reference not set to instance of object" on "model" object
My Controller class:
public ActionResult CreateProduct()
{
SetCateProductViewBag();
return View(new CateProdViewModel());
}
[HttpPost]
public ActionResult CreateProduct(CateProdViewModel model)
{
var ValidImageTypes = new String[]
{
"image/gif",
"image/jpeg",
"image/jpg",
"image/pjpeg",
"image/png"
};
if (model.ImageUpload == null || model.ImageUpload.ContentLength == 0)
{
ModelState.AddModelError("ImageUpload", "This Field is required.");
}
else if (!ValidImageTypes.Contains(model.ImageUpload.ContentType))
{
ModelState.AddModelError("ImageUload", "Please choose either a GIF,jpg or png type of file.");
}
if (ModelState.IsValid)
{
var prod = new Product
{
// CategoryName =model.category.CategoryName,
//CategoryDescription=model.category.CategoryDescription,
//CategoryId=model.CategoryId,
ProductName = model.ProductName,
ProductDescription = model.ProductDescription,
Model = model.Model,
ProductPrice = model.ProductPrice,
AvailableForSale = model.AvailableForSale,
Shippable = model.Shippable,
AvailableStock = model.AvailableStock,
ProductPicture = model.ProductPicture
};
SetCateProductViewBag(prod.CategoryId);
if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
{
var UploadDir = "~/Uploads";
var ImagePath = Path.Combine(Server.MapPath(UploadDir), model.ImageUpload.FileName);
var ImageUrl = Path.Combine(UploadDir, model.ImageUpload.FileName);
model.ImageUpload.SaveAs(ImagePath);
prod.ProductPicture = ImageUrl;
}
productContext.product.Add(prod);
productContext.SaveChanges();
return RedirectToAction("CategoryIndex");
}
return View(model);
}
CateProdViewModel class:
public class CateProdViewModel
{
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public string CategoryDescription { get; set; }
public string ProductName { get; set; }
public string ProductDescription { get; set; }
public int AvailableStock { get; set; }
public decimal ProductPrice { get; set; }
public string Model { get; set; }
public bool AvailableForSale { get; set; }
public bool Shippable { get; set; }
[DataType(DataType.ImageUrl)]
public string ProductPicture { get; set; }
public int SelectedValue { get; set; }
[DataType(DataType.Upload)]
public HttpPostedFileBase ImageUpload { get; set; }
public virtual Category category { get; set; }
[Display(Name="Product Categories")]
public virtual ICollection<Category> categories { get; set; }
}
Entity classes for Category and Product:
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public string ProductDescription { get; set; }
public int AvailableStock { get; set; }
public decimal ProductPrice { get; set; }
public string Model { get; set; }
public bool AvailableForSale { get; set; }
public bool Shippable { get; set; }
public string ProductPicture { get; set; }
public int CustomerId { get; set; }
public int CategoryId { get; set; }
public virtual Category category { get; set; }
}
public class Category
{
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public string CategoryDescription { get; set; }
public virtual ICollection<Product> product { get; set; }
}
My View:
#model SmartShoppingCart.Models.CateProdViewModel
#{
ViewBag.Title = "CreateProduct";
}
<h2>Create Product</h2>
<form action="" method="post" enctype="multipart/form-data">
<div>
#Html.LabelFor(m=>m.CategoryId,"Category")
#Html.DropDownList("CategoryId",ViewBag.categories as SelectList, string.Empty)
#Html.ValidationMessageFor(m=>m.CategoryId)
</div>
<div>
#Html.HiddenFor(m=>m.CategoryId)
</div>
<div>
#Html.LabelFor(m=>m.ProductName)
#Html.TextBoxFor(m=>m.ProductName)
#Html.ValidationMessageFor(m=>m.ProductName)
</div>
<div>
#Html.LabelFor(m=>m.ProductDescription)
#Html.TextBoxFor(m=>m.ProductDescription)
#Html.ValidationMessageFor(m=>m.ProductDescription)
</div>
<div>
#Html.LabelFor(m=>m.Model)
#Html.TextBoxFor(m=>m.Model)
#Html.ValidationMessageFor(m=>m.Model)
</div>
<div>
#Html.LabelFor(m=>m.ProductPrice)
#Html.TextBoxFor(m=>m.ProductPrice)
#Html.ValidationMessageFor(m=>m.ProductPrice)
</div>
<div>
#Html.LabelFor(m=>m.AvailableForSale)
#Html.TextBoxFor(m=>m.AvailableForSale)
#Html.ValidationMessageFor(m=>m.AvailableForSale)
</div>
<div>
#Html.LabelFor(m=>m.Shippable)
#Html.TextBoxFor(m=>m.Shippable)
#Html.ValidationMessageFor(m=>m.Shippable)
</div>
<div>
#Html.LabelFor(m=>m.AvailableStock)
#Html.TextBoxFor(m=>m.AvailableStock)
#Html.ValidationMessageFor(m=>m.AvailableStock)
</div>
<div>
#Html.LabelFor(m=>m.ImageUpload)
#Html.TextBoxFor(m => m.ImageUpload, new {type="file" })
</div>
<div>
<button type="submit" value="Add" ></button>
</div>
</form>
private void SetCateProductViewBag(int? CateId = null)
{
if (CateId == null)
{
ViewBag.Categories = new SelectList(productContext.category, "CategoryId", "CategoryName");
}
else
{
ViewBag.Categories = new SelectList(productContext.category.ToArray(),"CategoryId","CategoryName",CateId);
}
}
Your error occurs because your model is null on post back. The model is null because it contains a property named Model and the parameter name of the action method is also named model which is confusing the poor DefaultModelBinder. Either change the name of the property to something else or change the parameter name in your post action method to something else.
Why don't you change the first action to:
public ActionResult CreateProduct(CateProdViewModel model)
{
SetCateProductViewBag();
return View(model);
}
And your DefaultModelBinder will instantiate the model so it's never null.
Other than that, I need to know what you mean by saying When i execute my Create method. Since you don't have a Create method there. You have CreateProduct and you got 2 of them. Is this a POST or GET request?
I have a ViewModel as below:
public class CheckoutViewModel
{
public string ProductNumber { get; set; }
public string Name { get; set; }
public int Price { get; set; }
public Input UserInput;
public class Input
{
public string Email { get; set; }
public string Phone { get; set; }
}
}
And an action like this:
[HttpPost]
public ActionResult Index(CheckoutViewModel model)
{
// ...
return View();
}
And my model has bound as below:
#model GameUp.WebUI.ViewModels.CheckoutViewModel
#using (Html.BeginForm("Index", "Checkout", FormMethod.Post))
{
#Html.AntiForgeryToken()
<!-- some HTML -->
#Html.LabelFor(m => m.UserInput.Email)
#Html.TextBoxFor(m => m.UserInput.Email)
#Html.LabelFor(model => model.UserInput.Phone)
#Html.TextBoxFor(model => model.UserInput.Phone)
<button>Submit</button>
}
When I submit the form, the UserInput is null. I know ASP.NET MVC is able to bind nested types but in this code is not. Also I can get the Email and Phone values by:
var email = Request.Form["UserInput.Email"];
var phone = Request.Form["UserInput.Phone"];
Maybe I do something wrong! It's a simple model binding you can find everywhere in the web.
You forgot to put a setter in your UserInput, I don't think the setter is automatic. Anyway you can make it work by just putting a getter/setter in your UserInput and no need to do extra in your controller method:
public Input UserInput { get; set; }
Your complete model:
public class CheckoutViewModel
{
public string ProductNumber { get; set; }
public string Name { get; set; }
public int Price { get; set; }
public Input UserInput { get; set; }
public class Input
{
public string Email { get; set; }
public string Phone { get; set; }
}
}
I am new to MVC so here is my issue. I have a parent view and a partial view which is rendered inside it.
As a model I pass an IEnumerable to the parent view. I iterate thru the list and for each item i render the partial view having the list item as model. On the partial view I have a form which on a submit triggers a child action which accepts as parameter the type of the list. My issue is that the param comes always with it's values null.
These are my domain entities.
public class Contact
{
[Key]
public int IdContacts { get; set; }
public int UserId { get; set; }
public int CreatedByUserId { get; set; }
public int UpdatedByUserId { get; set; }
public int AddressId { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public long HomePhone { get; set; }
public long? WorkPhone { get; set; }
public bool IsRelated { get; set; }
public bool IsEmergency { get; set; }
public bool IsDeceased { get; set; }
public string Relationship { get; set; }
public DateTime EntryDate { get; set; }
public DateTime? ChangeDate { get; set; }
}
public class Address
{
[Key]
public int IdAddresses { get; set; }
public int CountryId { get; set; }
public int StateId { get; set; }
public int CreatedByUserId { get; set; }
public int UpdatedByUserId { get; set; }
public string Street { get; set; }
public string City { get; set; }
public long PostalCode { get; set; }
public string OfficeOrApt { get; set; }
public int AreaGroup { get; set; }
public int? SuperUserId { get; set; }
public DateTime EntryDate { get; set; }
public DateTime? ChangeDate { get; set; }
}
This is my view model
public class ContactModel
{
public Contact Contact { get; set; }
public Address Address { get; set; }
public bool IsEditMode { get; set; }
}
This is my parent view
#model IEnumerable<Cricket.WebUI.Models.ContactModel>
#{
ViewBag.Title = "Contacts";
}
<h2 align="center">
Contacts</h2>
<div class="iggr_container">
<div class="iggr_clear">
</div>
#foreach (var contact in Model)
{
ViewDataDictionary dictionary = new ViewDataDictionary();
string guid = (Guid.NewGuid()).ToString();
dictionary.Add("prefix", guid);
#Html.Hidden("Contact.Index", guid)
#Html.Hidden("Address.Index", guid)
#Html.Partial("ContactSummary", contact, dictionary)
<hr style="width: 385px;" align="left" />
}
</div>
This is my partial view
#model Models.ContactModel
<div class="iggr_clear">
</div>
#if (!Model.IsEditMode)
{
var prefixContact = "Contact[" + ViewData["prefix"] + "].";
var prefixAddress = "Address[" + ViewData["prefix"] + "].";
using (Html.BeginForm("Edit", "Contacts", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
TempData["ContactModelObject"] = Model;
<div>
<b>
#Html.Hidden(prefixContact + "FirstName", Model.Contact.FirstName);
#Html.Hidden(prefixContact + "LastName", new { name = "Contact" + ViewData["prefixContact"] + ".LastName" })
#Html.LabelFor(m => m.Contact.FirstName, Model.Contact.FirstName)
#Html.LabelFor(m => m.Contact.LastName, Model.Contact.LastName)
</b>
<div>
<span>Home Phone:</span>
#Html.Hidden(prefixContact + "HomePhone", Model.Contact.HomePhone)
#Html.LabelFor(m => m.Contact.HomePhone, Model.Contact.HomePhone.ToString())</div>
<div>
<span>Work Phone:</span>
#Html.Hidden(prefixContact + "WorkPhone", Model.Contact.WorkPhone)
<span>
#if (Model.Contact.WorkPhone == null)
{
#:N/A
}
else
{
#Html.LabelFor(m => m.Contact.WorkPhone, Model.Contact.WorkPhone.ToString())
}
</span>
</div>
<div>
#Html.Hidden(prefixAddress + "Street", Model.Address.Street)
#Html.LabelFor(m => m.Address.Street, Model.Address.Street)
</div>
<div>
#Html.Hidden(prefixAddress + "City", Model.Address.City)
#Html.Hidden(prefixAddress + "PostalCode", Model.Address.PostalCode)
#Html.LabelFor(m => m.Address.City, Model.Address.City) #Html.LabelFor(m => m.Address.PostalCode, Model.Address.PostalCode.ToString())
</div>
#Html.Hidden(prefixContact + "IsRelated", Model.Contact.IsRelated)
#if (Model.Contact.IsRelated)
{
<b>Family</b>
if (Model.Contact.IsEmergency || Model.Contact.IsDeceased)
{
<b>/</b>
}
}
#Html.Hidden(prefixContact + "IsEmergency", Model.Contact.IsEmergency)
#if (Model.Contact.IsEmergency && !Model.Contact.IsDeceased)
{
<b>Emergency</b>
}
#Html.Hidden(prefixContact + "IsDeceased", Model.Contact.IsDeceased)
#if (Model.Contact.IsDeceased)
{
<b>Deceased</b>
}
<input type="submit" name="button" value="Edit" class="iggr_button_edit" style="margin-left: 150px;" />
</div>
}
}
And finally my controller class
public class ContactsController : Controller
{
[HttpGet]
public ActionResult Index()
{
ContactsRepository repository = new ContactsRepository();
CDE.User user = (from u in repository.Users where u.IdUsers == 1 select u).FirstOrDefault();
var contacts = (from u in repository.Users
join c in repository.Contacts on new { UserId = u.IdUsers } equals new { UserId = c.UserId }
join a in repository.Addresses on new { AddressId = c.AddressId } equals new { AddressId = a.IdAddresses }
select new ContactModel()
{
Contact = c,
Address = a
}).AsEnumerable();
return View("Contacts", contacts);
}
[HttpPost]
[ActionName("Edit")]
[#ActionFilter(ActionInvokerType = "button", ActionInvokerValue = "Edit")]
public ViewResult Edit(ContactModel contact)
{
//Here contact.Contact comes as null same for contact.Address
return View("Contacts", null);//Ignore this line
}
}
I have a feeling that your prefix structure is interfering with the binding that normally happens in MVC. You could use a custom model binding implementation, or find a way to do without your prefixes.