ASP.NET MVC生成表格后 [英] ASP.NET MVC generate post forms

查看:65
本文介绍了ASP.NET MVC生成表格后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在寻找一个MVC的问题,那就是,我要2输入文本框在用户输入行数和列数。进入后,用户将preSS Generate按钮,将在接下来的操作方法产生所需的文本框数。例如,如果用户输入2行3列,然后提交后的第二种形式将包含表格形式6的文本框,最重要的应该有一个提交按钮,通过它我可以得到的职位从所有6个文本框中的值采取行动。

I'm just looking for a problem in MVC, that is, I want 2 input text boxes in which user will enter number of rows and columns. After entering, the user will press the generate button and the required number of text boxes will be generated on the next action method. For example, if the user enters 2 rows and 3 columns then after submit the second form will contain 6 text boxes in tabular form and most importantly there should be a submit button through which I can get the values from all 6 text boxes in the POST action.

下面是我的code

型号:

    [Required]
    [Display(Name = "Rows")]
    [Range(1, 10, ErrorMessage = "Number of Rows must be between 1 to 10")]
    public int NumberofRows { get; set; }

    [Required]
    [Display(Name = "Columns")]
    [Range(1, 4, ErrorMessage = "Number of Columns must be between 1 to 4")]
    public int NumberofColumns { get; set; }

    public List<int> EnteredNumberRows { get; set; }
    public List<int> EnteredNumberColumns { get; set; }

控制器:

/*Index action is one, in which the number of rows and columns are displayed. After entering number of rows and columns it redirects it to the Enter action containing required number of rows and columns*/
public class HomeController : Controller
{
    DataMineModel homeDataMineModel = new DataMineModel();
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Index(DataMineModel model)
    {
        TempData["NumofRows"] = model.NumberofRows;
        TempData["NumofColumns"] = model.NumberofColumns;

        return RedirectToAction("Enter");
    }

    public ActionResult Enter()
    {
        homeDataMineModel.EnteredNumberRows = new List<int>((int)TempData["NumofRows"]);
        homeDataMineModel.EnteredNumberColumns = new List<int>((int)TempData["NumofColumns"]);

        return View(homeDataMineModel);
    }

    [HttpPost]
    public ActionResult Enter(DataMineModel viewModel)
    {

        return View();
    }
}

查看:

指数:

@using (Html.BeginForm()) 
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
    <br />
    <h4>Please enter the number of Rows and Columns.</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(model => model.NumberofRows, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.NumberofRows, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.NumberofRows, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.NumberofColumns, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.NumberofColumns, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.NumberofColumns, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Enter" class="btn btn-success" />
        </div>
    </div>
</div>
  }

输入:

@using (Html.BeginForm("Enter", "Home", FormMethod.Post))
{
<div class="row">
    @for (int i = 0; i < Model.EnteredNumberColumns.Capacity; i++)
    {
        <div class="col-md-3">
            <div class="row">
                @for (int k = 0; k < Model.EnteredNumberRows.Capacity; k++)
                {
                    <br />
                        <input type="text" class="form-control" name="name" value="" />
                    <br />
                }
            </div>
        </div>
    }
</div>

     <input type="submit" class="btn btn-success" value="Classify the data"    />
   }



     
        
        
            
                
            
        
    


感谢。

推荐答案

,这不是MVC的一个问题。你可以写一些JS来获取用户输入并生成HTML表格按输入。您的JS也应有所为:

as suggested by Robert, this ain't a problem for MVC. You can write some JS to get user input and generate HTML tables as per the inputs. Your JS should be somewhat as:

$("body").on("change", "#coaLevelInput", function () {

        var l = $(this).val();
        var ht= "";
        for (var i = 1; i <= l ; i++)
        {
            ht= ht + "<div .... here you should set your CSS classes'>Code Lenght at Level" + i + "</label><span class=''><input class=''></span></div></div>";

        }
        $("#coaInputs").html(ht);

    });

这篇关于ASP.NET MVC生成表格后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆