Lionel Slade

Lionel Slade

  • NA
  • 2
  • 434

Read values from Labels

Dec 2 2016 5:16 AM
How do I get the values in my controller from the labels?
 
MVC Page
 
@using (Html.BeginForm("EditSubscriptionCurrent", "Subscriptions", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<td class="editor-field">
Subsciption Package Sent: <input id="cbSubPackSent" name="cbSubPackSent" type="checkbox" value="checked" />
</td>
<td class="editor-field">
Subsciption Package Sent By: <label id="UserNameUN" name="UserNameUN">@ViewBag.UserName</label>
</td>
<td class="editor-field">
Subsciption Package Sent Date: <label id="DateTimeDT" name="DateTimeDT">@ViewBag.DateTime</label>
</td>
<td>
<input type="submit" value="Save" />
</td>
}
 
 
Controller
 
string searchString = Request.Form["SearchString"];
//var subscriptions = subscriptionsAll.Where()
int count;
IQueryable subscriptions = FilterSubscriptions2(subscriptionsAll, _subscriptionPackSerach, currentFilter, out count);
foreach (SUBSCRIPTION subscription in subscriptions)
{
//update subPackStatus
var r = (Request.Form["cbSubPackSent"] == "checked") ? true : false;
bool checkedStatus = Convert.ToBoolean(r);
subscription.SubPackSent = checkedStatus;
var userName = Request.Form["UserNameUN"];
var UN = ViewBag.UserName;
subscription.SubPackSentBy = userName;
var dt2 = ViewBag.DateTime;
DateTime dt = Convert.ToDateTime(Request.Form["DateTimeDT"]);
subscription.SubPackSentDate = dt;
ctx.Entry(subscription).State = EntityState.Modified;
}
//MvcApplication._subscriptionsPackUpdate = subscriptionsPackUpdate;
ctx.SaveChanges();
 
 
UserName & dt return null.  r returns a value
 
 

Answers (2)