Click here to Skip to main content
15,667,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im use two modal PagedList and Post in class ViewModel
when use in control ViewModel

public class Post
       public int ID_Post { set; get; }
       public string FNamePost { set; get; }


public class ViewModel

       public IEnumerable<Mvc_baker.Areas.admin.Models.Post> Post { get; set; }
       public PagedList.IPagedList<Post> Postpoages { get; set; }

@model Mvc_baker.Areas.admin.Models.ViewModel 
    Layout = null;
    ViewBag.Title = "AddPostUser";
    Layout = "~/Areas/admin/Views/Shared/_AdminLayout.cshtml";

@using (Html.BeginForm( new { @class = "form-horizontal" }))
 <td class="tdtext">
                                            @Html.TextBoxFor(m => m.FNamePost , new { id = "Name", @style = "width: 175px;" })
                                            @Html.ValidationMessageFor(x => x.FNamePost , null, new { @class = "help-inline" })


i see this error
'Mvc_baker.Areas.admin.Models.ViewModel' does not contain a definition for 'FNamePost' and no extension method 'FNamePost' accepting a first argument of type 'Mvc_baker.Areas.admin.Models.ViewModel' could be found (are you missing a using directive or an assembly reference?)

Line 40: @Html.TextBoxFor(m => m.FNamePost, new { id = "Name", @style = "width: 175px;" })

1 solution

Yes Dear the error is self explanatory.
See you have a model inside another model. That is Viewmodel contains a list of Posts, which has FNamePost and ID_Post as properties.
So in the viewpage when you need to access the properties of Post which is a list, you need to have a foreach loop for each item in @Model.PostPoages
@foreach(var item in Model.PostPoages)

As here in the view the Model contains the Postpages whosepropeties need to be accessed through the PostPoages only.
I hope youget here.
Post back queries if any.
Share this answer
saeed1364 28-Dec-14 11:22am    
how use in @Html.TextBoxFor(m => m.FNamePost , new { id = "Name", @style = "width: 175px;" })
please change up code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900