TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
pius joshua
NA
29
6.1k
How To Update Multiple Checked Box Rows In MVC 5
Jan 2 2021 10:39 AM
Hi, Happy New Year All. I am having this issues with updating selected input textbox in a table rows.
Here is my Code
My View Page
@using (Html.BeginForm("Update_Record", "Customer", FormMethod.Post))
{
<
table
id
=
"zero_config"
class
=
"table table-striped table-bordered display"
>
<
thead
>
<
tr
>
<
th
>
<
div
class
=
"icheck-primary"
>
<
input
type
=
"checkbox"
id
=
"Check_All"
/>
<
label
for
=
"ContractId"
>
</
label
>
</
div
>
</
th
>
<
th
>
Employee Name
</
th
>
<
th
>
Update Salary
</
th
>
<
th
>
Date
</
th
>
</
tr
>
</
thead
>
<
tbody
>
@for (int
i
=
0
; i
<
Model.Count
(); i++)
{
<
tr
>
<
td
>
<
div
class
=
"icheck-primary"
>
<
input
type
=
"checkbox"
id
=
"ContractId"
name
=
"contId"
value
=
"@Model[i].ContractId"
/>
<
label
for
=
"ContractId"
>
</
label
>
</
div
>
</
td
>
<
td
>
@Html.DisplayFor(
modeli
=
>
Model[i].Customer.Name)
</
td
>
<
td
>
<
input
type
=
"number"
step
=
"0.01"
class
=
"form-control"
id
=
"@Model[i].ContractId"
value
=
""
name
=
"TxtPayout"
max
=
""
/>
</
td
>
<
td
>
<
input
type
=
"date"
id
=
"@Model[i].ContractId"
value
="@DateTime.Now.ToString("
yyyy
-MM-dd")"
name
=
"TxtDatePaid"
class
=
"form-control"
/>
</
td
>
</
tr
>
}
</
tbody
>
</
table
>
<
input
type
=
"submit"
value
=
"Update Record"
class
=
"btn btn-primary"
/>
}
My Controller [HttpPost]
public
ActionResult Update_Record(System.Web.Mvc.FormCollection form)
{
string
[] contid = form.GetValues(
"contId"
);
decimal
total = 0;
// to get the total salaries
int
cnt = 0;
//Count Affected Rows
if
(contid !=
null
)
{
string
[] payout = form.GetValues(
"TxtPayout"
);
string
[] datepaid = form.GetValues(
"TxtDatePaid"
);
for
(
int
i = 0; i < contid.Length; i++)
{
decimal
salary = Convert.ToDecimal(payout[i]);
DateTime dt = Convert.ToDateTime(datepaid[i]);
total += salary;
//Convert.ToDecimal(payout[i]);
cnt++;
}
TempData[
"Message"
] =
string
.Format(
"Successfully Updated with {0} record(s) affected Total Payout: {1}"
, cnt, total);
}
getContract();
return
View(ViewBag.gct);
}
If i check the entire row and update, it works. but if i check any of the rows, it throws up error. What i want to achieve it to get the input values of only the rows i check instead of getting the entire input values of the input text boxes. Kindly Assist me with.. Thanks for your valued time..
Reply
Answers (
1
)
how to populate data into grid view items then insert into database?
Xml file to table in asp. Net?