简体   繁体   English

如何在ASP.NET MVC 3应用程序中添加文本框和列以在其中动态保存文本

[英]How to add a text box and a column to save text in it dynamically in ASP.NET MVC 3 application

I have to add a button which when clicked creates a new text box where I can add some text and save it in database. 我必须添加一个按钮,单击该按钮时会创建一个新的文本框,在其中可以添加一些文本并将其保存在数据库中。

For example- I click button thrice it will create 3 text boxes and 3 new columns in database to save them. 例如-我单击三次按钮,它将在数据库中创建3个文本框和3个新列以保存它们。

Application is in ASP.NET MVC 3 and Entity Framework 4.3.1. 应用程序在ASP.NET MVC 3和Entity Framework 4.3.1中。 Is it possible to do that using EF as it maps to static classes? 使用EF映射到静态类是否可以做到这一点?

    You can achieve this by following steps:
    //View page
    1)Write a function which creates a textbox and render in div.
    Something like this:

    <input id="btnAdd" type="button" value="Add" />
    <div id="TextBoxContainer">
    //Area of textboxes
    </div>
    <br />


    $(function () {
        $("#btnAdd").bind("click", function () {
            var div = $("<div />");
            div.html(GetTextBox(""));
            $("#TextBoxContainer").append(div);
        });

    });
    function GetTextBox(value) {
        return '<input name = "TextBox" type="text" />'
    }


    //Server side code
    Write an event handler on button click which adds three columns in the database.  
This could be done either by writing stored procedure or create statement. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM