Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

c# - Save Json object to SQL via dynamic textboxes mvc

I have a button when clicked will add a field group that is a group of textboxes. How do I save all the data from this dynamic text fields to one column in SQL server. Maybe as an array or a Json object.

<form method="post" action="submit.php">
        
<div class="form-group fieldGroup">
    <div class="input-group">
        <input type="text" name="name[]" class="form-control" placeholder="Enter name"/>
        <input type="text" name="email[]" class="form-control" placeholder="Enter email"/>
        <div class="input-group-addon"> 
            <a href="javascript:void(0)" class="btn btn-success addMore"><span class="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span> Add</a>
        </div>
    </div>
</div>

<input type="submit" name="submit" class="btn btn-primary" value="SUBMIT"/>

</form>

<!-- copy of input fields group -->
<div class="form-group fieldGroupCopy" style="display: none;">
<div class="input-group">
    <input type="text" name="name[]" class="form-control" placeholder="Enter name"/>
    <input type="text" name="email[]" class="form-control" placeholder="Enter email"/>
    <div class="input-group-addon"> 
        <a href="javascript:void(0)" class="btn btn-danger remove"><span class="glyphicon glyphicon glyphicon-remove" aria-hidden="true"></span> Remove</a>
    </div>
</div>
$(document).ready(function(){
//group add limit
var maxGroup = 10;

//add more fields group
$(".addMore").click(function(){
    if($('body').find('.fieldGroup').length < maxGroup){
        var fieldHTML = '<div class="form-group fieldGroup">'+$(".fieldGroupCopy").html()+'</div>';
        $('body').find('.fieldGroup:last').after(fieldHTML);
    }else{
        alert('Maximum '+maxGroup+' groups are allowed.');
    }
});

//remove fields group
$("body").on("click",".remove",function(){ 
    $(this).parents(".fieldGroup").remove();
});
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...