从局部视图创建元素后,主视图消除了过滤器

时间:2012-03-21 21:18:18

标签: asp.net-mvc-3 partial-views

宓麻烦是这样的:我有一个名为“创建”的视图,它指的是促销的创建。根据用户的不同,每个促销都有Genres,因此,当我进入“创建促销”时,我有一个列表(下拉列表)与用户的类型,但如果没有一个相关的类型我必须创建它而不离开当前页面,所以我使用局部视图创建新类型,我将其插入主视图(创建促销)它确实有效,但在创建类型后,主视图显示所有类型,而不仅仅是那些对应的当前用户。

这是主要观点:

@model Points2Pay.Models.Promocion

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>


<script type="text/javascript">

$(document).ready(function () {

    $(".slidingDiv").hide();
    $(".show_hide").show();

    $('.show_hide').click(function () {
        $(".slidingDiv").slideToggle();
    });

});

@using (Html.BeginForm())
{

        <a href="#" class="show_hide">Show/hide</a>
        <div class="slidingDiv" id="partialView">
        @{Html.RenderAction("Create2", "Genre");}
        </div>
}

@using (Html.BeginForm("Create","StoreManager"))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Promocion</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.GenreId, "Genre")
        </div>
        <div class="editor-field" id="DROPDOWN">
            @Html.DropDownList("GenreId", String.Empty)
            @Html.ValidationMessageFor(model => model.GenreId)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Title)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Title)
            @Html.ValidationMessageFor(model => model.Title)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Price)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Price)
            @Html.ValidationMessageFor(model => model.Price)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Puntos)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Puntos)
            @Html.ValidationMessageFor(model => model.Puntos)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.PromocionArtUrl)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.PromocionArtUrl)
            @Html.ValidationMessageFor(model => model.PromocionArtUrl)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>`

这是次要观点

    @model Points2Pay.Models.Genre

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

        <legend>New Genre</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Description)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>



        <p>
            <input type="submit" value="Create new Genre" />
        </p>

}

这是控制器

[ChildActionOnly]
public ActionResult Create2()
{

    return PartialView("Create2");

} 



//
// POST: /Genre/Create2

[HttpPost]
public ActionResult Create2(Genre genre)
{
    var ComercioActual = (Guid)System.Web.Security.Membership.GetUser().ProviderUserKey;
    if (ModelState.IsValid)
    {
        genre.ComercioId = ComercioActual;
        db.Genres.Add(genre);
        db.SaveChanges();
        return PartialView("Create2");


    }

    return PartialView("Create2");
}

希望你能帮助我。

0 个答案:

没有答案