English 中文(简体)
积极增加主编,加入目前关于减少变化的网页
原标题:dynamically add EditorTemplates to current page, on dropdown change

I currently have a 3 step wizard.

Step 1: takes some details I need and has a dropdown where you select the number of packages

Step 2: depending on how many packages you selected this step shows you the required number of editors for packages

www.un.org/spanish/ecosoc

我被告知,我需要把步骤1 &步骤2合并起来,但我对如何与mvc和razor一道这样做感到痛心,因为它只是关于你模式的要人。

这样做的最佳方式是什么?

究竟是向自己提交该页,还是采取专门行动,说明需要多少包件,还是可以用麻省做吗?

增 编

最佳回答

我的做法如下:

www.un.org/Depts/DGACM/index_spanish.htm 为一揽子浏览(PackageRow.cshtml)创建部分

@model IEnumerable<PackageViewModel>
<div class="editorRow">
@using (Html.BeginCollectionItem("packages"))
{
    @Html.TextBoxFor(x => x.WhateverYouNeed) 
}
</div>

www.un.org/Depts/DGACM/index_spanish.htm 在用户选择浏览量时,通过jax将包装分成如下:

@Html.ActionLink("Go!", "AddPackages", null, new { id = "addPackages" })

<div id="editorRows"></div>

<script type="text/javascript">
$(document).ready(function () {
        $("#addPackages").click(function () {
            $.ajax({ url: this.href, cache: false, success: function (html) {
                $("#editorRows").append(html); // add the number of rows you need here
            }
            }); return false;
        });
        $("a.deleteRow").live("click", function () { $(this).parents("div.editorRow:first").remove(); return false; });
    });  
</script>   

www.un.org/Depts/DGACM/index_spanish.htm 通过你的控制器添加部分内容:

public ActionResult AddPackages()
{
    return PartialView("PackageRow", new PackageViewModel { ... });
}

www.un.org/Depts/DGACM/index_spanish.htm Save the data

 [Authorize]
 [HttpPost]
        public ActionResult CreatePackages(int id, FormCollection fc)
        {

            int nrKeys = fc.AllKeys.Count();
            int i = 0;

            int interations = (nrKeys / 2);

            foreach (var key in fc.AllKeys)
            {

                if (nrKeys <= i)
                    break;

                if (i != 0)
                {
                    string value1 = fc[i];
                    string value2 = fc[i + 1];
                   ...
                }
                else
                {
                    i++;
                }

           ...
问题回答

暂无回答




相关问题
How to update shared view adminheader.cshtml from a model

I ve added a drop down into my shared adminheader.cshtl view and it needs to be dynamically updated from data from a table. So when I use another view like routeplan.cshtml I load the view from ...

ASP.NET MVC Razor view engine

After reading Scott Guthrie s blog entry about the new Razor view engine for ASP.NET MVC and reading this question comparing the available view engines. Razor seems to address most of the problems ...

Client Id for Property (ASP.Net MVC)

I m trying to do a label for a TextBox in my View and I d like to know, how can I take a Id that will be render in client to generate scripts... for example: <label for="<%=x.Name.ClientId%>"...

Get Current Area Name in View or Controller

How do you get the current area name in the view or controller? Is there anything like ViewContext.RouteData.Values["controller"] for areas?

MVC which submit button has been pressed

I have two buttons on my MVC form: <input name="submit" type="submit" id="submit" value="Save" /> <input name="process" type="submit" id="process" value="Process" /> From my Controller ...

热门标签