如何在mvc中添加两个模态 [英] how add two modal in mvc
问题描述
我在使用控件时使用两个模态PagedList和Post ViewModel
ViewModel
im use two modal PagedList and Post in class ViewModel
when use in control ViewModel
public class Post
{
[Key]
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" })
</td>
}
}
i看到这个错误
'Mvc_baker.Areas.admin.Models.ViewModel'确实如此不包含'FNamePost'的定义,并且没有可以找到接受类型'Mvc_baker.Areas.admin.Models.ViewModel'的第一个参数的扩展方法'FNamePost'(你是否缺少using指令或汇编引用?)
第40行:@ Html.TextBoxFor(m => m.FNamePost,new {id =Name,@ style =width:175px; })
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;" })
推荐答案
是的,亲爱的错误是自我解释的。
看到你在另一个模型中有一个模型。即Viewmodel包含一个帖子列表,其中包含FNamePost和ID_Post作为属性。
所以在视图页面中当你需要访问Post的属性列表时,你需要为@ Model.PostPoages中的每个项目设置一个foreach循环
like : -
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
like:-
@foreach(var item in Model.PostPoages)
{
item.FNamePost
}
在视图中,模型包含其名称需要的Postpages只能通过PostPoages访问。
我希望你在这里。
谢谢。
回复查询,如果有的话。
As here in the view the Model contains the Postpages whosepropeties need to be accessed through the PostPoages only.
I hope youget here.
Thanks.
Post back queries if any.
这篇关于如何在mvc中添加两个模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!