小编Fur*_*ica的帖子

如何用另一个替换局部视图?

我想显示"最新新闻"文章列表,并点击"阅读更多"链接,以显示所点击文章的完整内容.为此,我在Index.cshtml视图中使用局部视图.第一次显示"索引"视图时,将使用文章列表填充局部视图.我想要的是:重复使用相同的局部视图来显示完整的文章,点击.

出于某种原因,我无法做到这一点,我不明白为什么.使用调试器和Firebug,我可以捕获没有错误.此外,应用程序遍历所有步骤,甚至似乎显示_Details局部视图,但实际上,在屏幕上仍然是列表.

谢谢你指出我的错误.

编辑:

我在_Layout.cshtml中引用了所有必需的脚本:jquery-1.8.2.min.js,jquery-ui-1.8.24.custom.min.js,jquery.ui.core.min.js,jquery.validate. min.js,jquery.validate.unobtrusive.min.jsjquery.unobtrusive-ajax.js以及web.config中的"UnobtrusiveJavaScriptEnabled"="true".

Index.cshtml

@model MyApp.ViewModels.NewsViewModel

<div id="content" class="content_style"> 
   <text>Some static content</text>
   <div class="active_part">
        @Html.Partial("_List", Model.NewsList)
   </div><!-- end active_part -->
</div><!-- end content -->
Run Code Online (Sandbox Code Playgroud)

_List.cshtml

@model IEnumerable<MyApp.Models.News>
@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "active_part", InsertionMode = InsertionMode.Replace }))
{
    foreach (var item in Model)
    {
    <h2 class='title">
    @Ajax.ActionLink(item.Title, "Details", "News", new { id = item.News_ID }, new AjaxOptions { UpdateTargetId = "active_part" }, null)
        </h2>

        <div class="body">
            @Html.Raw(item.Body)
            @Ajax.ActionLink("Read more", "Details", …
Run Code Online (Sandbox Code Playgroud)

partialviews asp.net-mvc-3

5
推荐指数
1
解决办法
5663
查看次数

MVC3 - 帖子上的模型字段为空(使用viewmodel)

在MVC3应用程序中,我有一个具有奇怪行为的实体:"创建"操作正常,但"编辑"操作失败:在提交时,我获取所有字段为空的模型.

我搜索了关于这个错误的建议,似乎ViewModel可能是原因,但我看不出我的任何问题.正如我之前所说,创作工作正常!

请帮帮忙,谢谢!

模型:

    public partial class tblEmployeur
{
    [Required(ErrorMessageResourceType = typeof(EmployeurResources), ErrorMessageResourceName = "RequiredUserIDMessage")]
    [Display(ResourceType = typeof(EmployeurResources), Name = "UserIDDisplay")]
    public System.Guid userID { get; set; }

    [Required(ErrorMessageResourceType = typeof(EmployeurResources), ErrorMessageResourceName = "RequiredNomMessage")]
    [Display(ResourceType = typeof(EmployeurResources), Name = "NomDisplay")]
    public string nom { get; set; }

    [Required(ErrorMessageResourceType = typeof(EmployeurResources), ErrorMessageResourceName = "RequiredTypeSocMessage")]
    [Display(ResourceType = typeof(EmployeurResources), Name = "TypeSocDisplay")]
    public string type_soc { get; set; }

    [Required(ErrorMessageResourceType = typeof(EmployeurResources), ErrorMessageResourceName = "RequiredCodeRCMessage")]
    [Display(ResourceType = typeof(EmployeurResources), Name = "CodeRCDisplay")]
    public string …
Run Code Online (Sandbox Code Playgroud)

post viewmodel asp.net-mvc-3

2
推荐指数
1
解决办法
7128
查看次数

标签 统计

asp.net-mvc-3 ×2

partialviews ×1

post ×1

viewmodel ×1