I have a view bind with two models ...so I choose ViewModel
method to bind two models with a view ...but I am facing problem to create a view of Create
type ...but I am facing error ...FeedbackMix is ViewModel here...I have to pass query object for displaying something in the layout at the same time I have to make Create type view page ...
ERROR:
CS1061: 'FeedbackMixModel' does not contain a definition for 'Message' and no extension method 'Message' accepting a first argument of type 'FeedbackMixModel' could be found (are you missing a using directive or an assembly reference?)
Controller
public ActionResult Create()
{
var msg= db.Messages.ToList();
var feed = db.Feedbacks.ToList();
FeedbackMixModel vm = new FeedbackMixModel();
vm.allfeedbacks = feed;
//this is also create type view
return View(vm);
}
View
@model WebApplication5.Models.FeedbackMixModel
....
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
....
@Html.LabelFor(model => model.Message, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Message, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Message, "", new { @class = "text-danger" })
</div>
....
}
ViewModel
public class FeedbackMixModel
{
public List<UserManager> allUserManagers { get; set; }
public List<Feedback> allfeedbacks { get; set; }
public List<Package> allpackages { get; set; }
public List<Messages> allmessages { get; set; }
}
ERROR LINE
Line 16: @Html.LabelFor(model => model.Message, htmlAttributes: new { @class = "control-label col-md-2" })
FeedbackMixModel
you don't have aMessage
property or method – Hackerman