Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
there is one 2 text box one button when u insert something in 2 text box and click submit button it will desplay that text box value below again if u insert some more values to the text box and click submit button it will display below the first result ,how to take all the table values from view to controler
Posted

On each button click store your values in an Array, and pass it using AJAX to the action method,
JavaScript
var arr = [];
$("button").click(function() {
    arr.push($("textbox").val());  // insert into array
    $("p").text($("textbox").val());  // show textbox value below textbox
})

$.ajax({
    url: "/controller/getvalues"
    data: {values: arr}
    cache: false,
    success: function(data)
    {
        // done
    },
    error: function()
    {
        // error
    }
});

C#
public ActionResult GetValue(int[] values)
{
    // do something with values
}


-KR
 
Share this answer
 
v2
Comments
Member 11970398 3-Nov-15 2:41am    
not working these values will come dynamically no of times he enter text box and click submit it will dispaly below and the end there is insert button if he click it it will go to controler
Krunal Rohit 3-Nov-15 3:03am    
That's what I said, on each click of your button maintain the array for your textbox values. And on the click of Insert button, pass this array.

-KR
You can create model
C#
public class AbcModel
{
    public string textbox1 { get; set; };
    public string textbox2 { get; set; }

}
//Submit
SQL
public ActionResult SaveVlaues(list<abcmodel> Model)
{
    //perform you operation
}
</abcmodel>

Please check this link for detail
List of Model Object Post to Controller in ASP.NET MVC[^]
 
Share this answer
 
Comments
Member 11970398 3-Nov-15 2:49am    
no i am no taking about that
@**@
@foreach (var item in Model)
{
@**@
}

@Html.DisplayNameFor(model => model.TestName)
@Html.DisplayNameFor(model => model.QuestionName)
@Html.DisplayNameFor(model => model.Skill)
@Html.DisplayNameFor(model => model.Level)
@Html.DisplayNameFor(model => model.Percentage)
@Html.DisplayFor(modelItem => item.TestName)
@Html.DisplayFor(modelItem => item.QuestionName)
@Html.DisplayFor(modelItem => item.Skill)
@Html.DisplayFor(modelItem => item.Level)
@Html.DisplayFor(modelItem => item.Percentage)



}
<script type="text/javascript">
var current = 100;
function NotiFyUser() {
// current++;

var QnName = $('#QnName').val();
var NoOfqn = $('#NoOfqn').val();
var SkillId = $("#SkillId :selected").text();
var LevelId = $("#LevelId :selected").text();
var Percentage = $('#Percentage').val();
if (Percentage == 0) {
alert("Percentage can not be 0");
return false;
}
else if (Percentage <= current) {
$('#table tr:Last').after('
' + SkillId + '' + LevelId + '' + Percentage + '
');
$("#QnName").attr("disabled", "disabled");
$("#NoOfqn").attr("disabled", "disabled");
$('#TestName').val(QnName);
$('#Total').val(NoOfqn);
$('#TestName').attr("disabled", "disabled");
$('#Total').attr("disabled", "disabled");


} else {
alert("Sum exceeds 100 try to enter lower Percentage");
return false;
}
current = current - Percentage;
$('#Percentage').val(current);
console.log(Percentage);
console.log(current);
}



</script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900