Why when you click on input, nothing happens in the form? - c#

I'm making a small page where you can create users, change their password and delete them. The creation works well, but deleting and changing the password does not respond to clicking in any way. It works correctly through the postman. What could be the problem?
#page
#addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
#{
Layout = "Shared/_MonitoringLayout";
ViewData["PageTitle"] = "users";
}
#section MainBlock {
#{
if (#Model.Error != null)
{
<div>
<span style="color: red">#($"Error: {Model.Error}")</span>
</div>
}
else
{
<div>
<table style="max-width: 70%" class="m_table">
<thead class="m_table_header">
<tr>
<th style="width: 5%">
Id
</th>
<th style="width: 15%">
Name
</th>
<th style="width: 15%">
Login
</th style="width: 25%">
<th>
Action
</th>
</tr>
</thead>
<tbody>
#foreach (var rootUser in Model.RootUsers)
{
<tr>
<td>
#rootUser.Id
</td>
<td>
#rootUser.DisplayName
</td>
<td>
#rootUser.Login
</td>
<td>
<from method="post">
<div>
<lable>NewPassword:</lable>
<input type="password" name="password" required />
<input asp-page-handler="ChangePassword" value="Change" type="submit"/>
</div>
</from>
<from method="post">
<input asp-page-handler="DeleteUser" asp-route-id="#rootUser.Id" value="Delete" type="submit"/>
</from>
</td>
</tr>
}
</tbody>
</table>
</div>
<br />
}
<div>
<form method="post">
<h1>Create</h1>
<div class="input-container">
<input asp-for="CreateAccountRequest.DisplayName" type="text" required />
<lable asp-for="CreateAccountRequest.DisplayName">Name</lable>
</div>
<div class="input-container">
<input asp-for="CreateAccountRequest.Login" type="text" value="root" readonly/>
<lable asp-for="CreateAccountRequest.Login">Login</lable>
</div>
<div>
<input asp-for="CreateAccountRequest.Password" type="password" required/>
<lable asp-for="CreateAccountRequest.Password">Password</lable>
</div>
<button asp-page-handler="create" type="submit">Create</button>
</form>
</div>
}
};
[IgnoreAntiforgeryToken]
public class ServiceUsersModel : PageModel
{
public List<InternalAccountResponse> RootUsers { get; private set; }
[BindProperty]
public InternalCreateAccountV2Request CreateAccountRequest { get; set; }
protected async override Task<IActionResult> OnGet()
{
..Do
}
public async Task<IActionResult> OnPostCreateAsync()
{
..Do
}
public async Task<IActionResult> OnPostDeleteUserAsync(long id)
{
..Do
}
public async Task<IActionResult> OnPostChangePasswordAsync(string password)
{
..Do
}
}
I tried tracking requests through the developer tools in chrome and through debugging, requests just don't go away, although formaction="/monitoring/serviceusers?id=536&handler=deleteUser" is formed to delete and /monitoring/serviceusers?handler=ChangePassword" to change the password. If you send these requests through the postman, then they reach the service.

<form method="post">
<div>
<lable>NewPassword:</lable>
<input type="password" name="password" required />
<input asp-page-handler="ChangePassword" value="Change" type="submit"/>
</div>
</form>
<form method="post">
<input asp-page-handler="DeleteUser" asp-route-id="#rootUser.Id" value="Delete" type="submit"/>
</form>
<from> tag should be using the <form> tag

Related

The model directive may only occur once per document (adding buttons to lists problem) ASP.NET MVC Core C#

I'm trying to display a button because I need to add new information but there is a list within the file and it is not working
I am using ASP.NET Core MVC and C#.
It is something like this:
HTML File:
#model IEnumerable<MyApplication.Models.Clients>
<table class="table" id="Tabla4">
<thead>
<tr>
<th>
#Html.DisplayNameFor(model => model.CODE)
</th>
<th>
#Html.DisplayNameFor(model => model.NAME)
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.CODE)
</td>
<td>
#Html.DisplayFor(modelItem => item.NAME)
</td>
<td>
</td>
</tr>
}
</tbody>
</table>
My controller method:
public ActionResult Create()
{
List<Clients> clients = dbContext.GetClients().ToList();
return View(clients);
}
I want to add this in my HTML file:
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="CODE" class="control-label"></label>
<input asp-for="CODE" class="form-control" />
<span asp-validation-for="CODE" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="NAME" class="control-label"></label>
<input asp-for="NAME" class="form-control" />
<span asp-validation-for="NAME" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
I tried to add this:
#Model MyApplication.Models.Clients
I get this error:
The model directive may only occur once per document
How can I solve it?
EDIT:
My Client Model is this:
public class Clients{
public int CODE {get; set;}
public string NAME {get; set;}
}
If i put the button inside the HTML File it throws and error:
#model IEnumerable<MyApplication.Models.Clients>
<table class="table" id="Tabla4">
<thead>
<tr>
<th>
#Html.DisplayNameFor(model => model.CODE)
</th>
<th>
#Html.DisplayNameFor(model => model.NAME)
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.CODE)
</td>
<td>
#Html.DisplayFor(modelItem => item.NAME)
</td>
<td>
</td>
</tr>
}
</tbody>
</table>
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="CODE" class="control-label"></label>
<input asp-for="CODE" class="form-control" />
<span asp-validation-for="CODE" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="NAME" class="control-label"></label>
<input asp-for="NAME" class="form-control" />
<span asp-validation-for="NAME" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
It says:
IEnumerable<MyApplication.Models.Clients> does not contain a
definition CODE and no accesible extension method CODE
IEnumerable<MyApplication.Models.Clients> does not contain a
definition NAME and no accesible extension method NAME
EDIT #2
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label for="CODE" class="control-label"></label>
<input name="CODE" class="form-control" />
</div>
<div class="form-group">
<label for="NAME" class="control-label"></label>
<input name="NAME" class="form-control" />
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
EDIT #3:
Now it is throwing this error: Object reference not set to an instance of an object, in the foreach part:
#model IEnumerable<MyApplication.Models.Clients>
<div class="row">
<div class="col-md-4">
<form asp-action="Create" method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label for="CODE" class="control-label">Code:</label>
<input name="CODE" class="form-control" />
</div>
<div class="form-group">
<label for="NAME" class="control-label">Name:</label>
<input name="NAME" class="form-control" />
</div>
<div class="form-group">
<input type="submit" value="Insert" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<table class="table" id="Tabla4">
<thead>
<tr>
<th>
#Html.DisplayNameFor(model => model.CODE)
</th>
<th>
#Html.DisplayNameFor(model => model.NAME)
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.CODE)
</td>
<td>
#Html.DisplayFor(modelItem => item.NAME)
</td>
<td>
</td>
</tr>
}
</tbody>
</table>
Image:
[![image][1]][1]
This is my Controller Create HTTP METHOD:
public ActionResult Create([Bind] Clients clients)
{
try
{
if (ModelState.IsValid)
{
dbContext.InsertData(clients);
return RedirectToAction("Index");
}
return View(clients);
}
catch
{
return View();
}
}
You cannot use asp-for="..." when the model/value you are using does not have these properties. Your model is defined as IEnumerable<MyApplication.Models.Clients> as the value for the view is a List<MyApplication.Models.Clients> object. When you use <input asp-for="CODE"> it looks for a property CODE inside the IEnumerable<...> type. However, this interface does not have such a property.
In your case you don't need asp-for="". Instead you can use a "normal" <input> tag with the name="..." attribute you want, depending on the Create() action you have defined. The code can look like this:
<div class="form-group">
<label for="CODE" class="control-label">Code:</label>
<input name="CODE" class="form-control" />
</div>
That way the HTTP Request will have the field name CODE in the POST body or GET URL parameter list, depending on how you send the form. ASP.NET will automatically fill the values into the parameters of your Create() action for you.

How do I pass a selected ID to my SQL Database?

I am having trouble with this last part of my project. I have all of my SQL Table columns filled up except for this last part. I have two tables WorkSchedule and WorkShiftBid.
In WorkShiftBid, I have WorkShiftBidID,WSBidDateTime,WSBidStatus,WorkScheduleID,StaffID
I will be using Guid.NewGuid() for WorkShiftBidID, Datetime.now for WSBidDatetime, A hardcoded "pending" value for WSBidStatus, A viewbag for StaffID and I am trying to get the WorkScheduleID to work but to no avail.
For WorkSchedule, I am trying to get just the "WorkScheduleID" attribute just by using a button method asp-route-id="#item.WorkScheduleID" and it will redirect me to the Create page whereby I will select a Staff from the drop-down list and then save it to my WorkShiftBid table as it has a foreign key for "WorkScheduleID".
It would be helpful if someone could help me. Thank you.
Controller Code:
public IActionResult CreateWorkShift()
{
ViewData["StaffID"] = new SelectList(_context.Staff, "StaffID", "StaffName");
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> CreateWorkShift(Guid? id, [Bind("WorkShiftBidID,WSBidDateTime,WSBidStatus,WorkScheduleID,StaffID")] WorkShiftBidModel workShiftBidModel)
{
if (id != workShiftBidModel.WorkScheduleID)
{
return NotFound();
}
if (ModelState.IsValid)
{
workShiftBidModel.WSBidDateTime = DateTime.Now;
workShiftBidModel.WorkShiftBidID = Guid.NewGuid();
_context.Add(workShiftBidModel);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(DisplaySchedule));
}
ViewData["StaffID"] = new SelectList(_context.Staff, "StaffID", "StaffName", workShiftBidModel.StaffID);
return View(workShiftBidModel);
}
private bool WorkShiftBidModelExist(Guid id)
{
return _context.WorkSchedule.Any(e => e.WorkScheduleID == id);
}
Display WorkShift Page:
<h1 class="text-center"> Apply Workshifts</h1>
<hr />
<table class="table">
<thead>
<tr>
<th>
From (DateTime)
</th>
<th>
To (DateTime)
</th>
<th>
Day
</th>
<th>
Status
</th>
<th>
Work Descriptions
</th>
<th>
Branch
</th>
<th>
Manager
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.WorkScheduleFromDateTime)
</td>
<td>
#Html.DisplayFor(modelItem => item.WorkScheduleToDateTime)
</td>
<td>
#Html.DisplayFor(modelItem => item.WorkScheduleFromDateTime.DayOfWeek)
</td>
<td>
#Html.DisplayFor(modelItem => item.WorkScheduleStatus)
</td>
<td>
#Html.DisplayFor(modelItem => item.WorkDescriptions.WorkDescriptionName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Branches.BranchName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Staff.StaffName)
</td>
<td>
<form method="post">
<input type="submit" class="btn btn-primary btn-block" value="Bid" asp-route-id="#item.WorkScheduleID" asp-action="DisplaySchedule" asp-controller="PartTimer" />
</form>
<div class="form-group col-md-6">
<a asp-action="CreateWorkShift" asp-route-id="#item.WorkScheduleID" class="btn btn-success">Create</a>
</div>
</td>
</tr>
}
</tbody>
</table>
Create view page code:
<h1>Create</h1>
<h4>Work Shifts</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="CreateWorkShift">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="WorkScheduleID"/>
<div class="form-group">
<label asp-for="WSBidStatus" class="control-label"></label>
<input readonly asp-for="WSBidStatus" value="Pending" class="form-control"/>
<span asp-validation-for="WSBidStatus" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="StaffID" class="control-label"></label>
<select asp-for="StaffID" class="form-control" asp-items="ViewBag.StaffID"></select>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<input type="submit" value="Save" class="btn btn-primary btn-block" />
</div>
<div class="form-group col-md-6">
<a asp-action="ProfilePage" class="btn btn-secondary btn-block"><i class=" fa fa-table"></i>Back to List</a>
</div>
</div>
</form>
</div>
</div>
#section Scripts {
#{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
Do you mean you cannot get the WorkScheduleID in public async Task<IActionResult> CreateWorkShift(Guid? id, [Bind("WorkShiftBidID,WSBidDateTime,WSBidStatus,WorkScheduleID,StaffID")] WorkShiftBidModel workShiftBidModel).If so,you need to get and pass Id in public IActionResult CreateWorkShift.Here is a demo worked:
public IActionResult CreateWorkShift(int id)
{
List<Staff> list = new List<Staff> { new Staff { StaffID = 1, StaffName = "staff1" }, new Staff { StaffID = 2, StaffName = "staff2" } };
ViewData["StaffID"] = new SelectList(list, "StaffID", "StaffName");
WorkShiftBidModel w = new WorkShiftBidModel { WorkScheduleID = id };
return View(w);
}
result:

How to fix "<TModel>.Model.get returned null" in MVC app?

I'm doing this app with a login view and I have a User model that has Username and Password to fill in at the login (as regular). I get this eror at the using statement in the view:
System.Web.Mvc.WebViewPage<TModel>.Model.get returned null.
Before I had this implemented but I changed it because I'm using a sample template that uses inputs and spans instead of labelfor and editfor:
#using (Html.BeginForm("Authorise", "Login", FormMethod.Post))
{
<table>
<tr>
<td></td>
<td style="text-decoration:underline"></td>
</tr>
<tr>
<td>#Html.LabelFor(model => model.Username)</td>
<td>#Html.EditorFor(model => model.Username)</td>
</tr>
<tr>
<td>#Html.ValidationMessageFor(model => model.Username)</td>
<td></td>
</tr>
<tr>
<td>#Html.LabelFor(model => model.Password)</td>
<td>#Html.EditorFor(model => model.Password)</td>
</tr>
<tr>
<td></td>
<td>#Html.ValidationMessageFor(model => model.Password)</td>
</tr>
<tr>
<td colspan="2">
<label class="field-validation-error">#Html.DisplayFor(model => model.LoginMessage)</label>
</td>
</tr>
<tr>
<td><input type="submit" value="Login" /></td>
<td><input type="reset" value="Clean" /></td>
</tr>
</table>
}
Before the change everything was working fine.
I changed the view to this:
#using (Html.BeginForm("Authorise", "Login", FormMethod.Post))
{
<form class="login100-form validate-form">
<span class="login100-form-logo">
<i class="zmdi zmdi-landscape"></i>
</span>
<span class="login100-form-title p-b-34 p-t-27">
Log in
</span>
<div class="wrap-input100 validate-input" data-validate="Enter username">
<input class="input100" type="text" name="Username" placeholder="Username" value="#Model.Username">
<span class="focus-input100" data-placeholder=""></span>
</div>
<div class="wrap-input100 validate-input" data-validate="Enter password">
<input class="input100" type="password" name="Password" placeholder="Password" value="#Model.Password">
<span class="focus-input100" data-placeholder=""></span>
</div>
<div class="contact100-form-checkbox">
<input class="input-checkbox100" id="ckb1" type="checkbox" name="remember-me">
<label class="label-checkbox100" for="ckb1">
Remember me
</label>
</div>
<div class="container-login100-form-btn">
<button class="login100-form-btn">
Login
</button>
</div>
<div class="text-center p-t-90">
<a class="txt1" href="#">
Forgot Password?
</a>
</div>
</form>
}
Controller:
public ActionResult Index()
{
using (FITMEContext db = new FITMEContext())
{
}
return View();
}
//For login
[HttpPost]
public ActionResult Authorise(User user)
{
using (FITMEContext db = new FITMEContext())
{
var userDetail = db.Users.Where(x => x.Username == user.Username && x.Password == user.Password).FirstOrDefault();
if (userDetail == null)
{
user.LoginMessage = "Invalid username or password";
return View("Index", user);
}
else
{
Session["UserId"] = user.UserId;
Session["UserName"] = user.Username;
return RedirectToAction("Index", "Home");
}
}
}
Model:
public partial class User
{
public int UserId { get; set; }
[DisplayName("User name")]
[Required(ErrorMessage = "Please fill in the user name")]
public string Username { get; set; }
[Required(ErrorMessage = "Please fill in the password")]
[DataType(DataType.Password)]
public string Password { get; set; }
public string LoginMessage { get; set; }
}
Any help would be appreciated. Thanks.
In the "Index" method you're calling View() without arguments. That's why Model == null
One of possible solutions is to create default model object and pass it to the view:
return View("Index", new User())
The helper method #Html.EditorFor(model => model.Username) would have been checking if Model is null before trying to access it. Now that you are rendering the values yourself, instead of with the helper methods, you will need to explicitly add null checks.
<input class="input100" type="text" name="Username" placeholder="Username" value="#(Model == null ? "" : Model.Username)">
As an alternative, you can still use the helper methods and specify the class of the input:
#Html.EditorFor(model => model.Username, new { #class = "input100" })
I now have changed to this below but the submit button just refreshes the page I don't know why. It was working in the other layout. Any tip on this? Seems an easy fix
<div class="wrap-login100">
<form class="login100-form validate-form">
<span class="login100-form-logo">
<i class="zmdi zmdi-landscape"></i>
</span>
<span class="login100-form-title p-b-34 p-t-27">
Log in
</span>
<div class="wrap-input100 validate-input" data-validate="Enter username">
<input class="input100" type="text" name="Username" placeholder="Username" value="#(Model == null ? "" : Model.Username)" />
<span class="focus-input100" data-placeholder=""></span>
</div>
<div class="wrap-input100 validate-input" data-validate="Enter password">
<input class="input100" type="text" name="Username" placeholder="Username" value="#(Model == null ? "" : Model.Password)" />
<span class="focus-input100" data-placeholder=""></span>
</div>
<div class="contact100-form-checkbox">
<input class="input-checkbox100" id="ckb1" type="checkbox" name="remember-me">
<label class="label-checkbox100" for="ckb1">
Remember me
</label>
</div>
#*<div class="container-login100-form-btn">
<button class="login100-form-btn">
Login
</button>
</div>*#
<input type="submit" value="Login" />
<div class="text-center p-t-90">
<a class="txt1" href="#">
Forgot Password?
</a>
</div>
</form>
</div>

How to post data to razor page code behind asp.net core

I want to implement a bulk operation function, but I cannot post my data to the razor page code behind, anyone can help? Please check my code below
<form method="post" asp-page="./Index">
<div class="row">
<div class="col-md-12">
<table class="table table-hover table-bordered" style="margin-top:15px;">
<thead>
<tr class="info">
<th></th>
<th>
<a asp-page="./Index" asp-route-sortOrder="#Model.NumberSort">
#Html.DisplayNameFor(model => model.Products[0].Number)
</a>
</th>
<th>
#Html.DisplayNameFor(model => model.Products[0].Name)
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model.Products)
{
<tr>
<td>
#Html.CheckBoxFor(modelItem => item.Checked)
</td>
<td class="success">
#Html.DisplayFor(modelItem => item.Number)
</td>
<td>
#Html.DisplayFor(modelItem => item.Name)
</td>
<td>
<a asp-page="./Details" asp-route-id="#item.ID" class="btn btn-info">details</a>
<a asp-page="./Edit" asp-route-id="#item.ID" class="btn btn-warning">edit</a>
<a asp-page="./Delete" asp-route-id="#item.ID" class="btn btn-danger">delete</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-md-10">
#{
var items = Model.Products.Where(x => x.Checked);
}
<input type="submit" name="bulkUpload" value="bulk upload" asp-route-data="#items"/>
</div>
</div>
</form>
public async Task OnPostAsync(List<Product> upload)
{
}
You need to render your products in such way that the Modelbinder will be able to pick them up on form submit and pass them into the codebehind.
Something like this (done by hand so it might not compile at first):
#{
for (int i = 0; i < Model.Products.Count; i++)
{
<input type="checkbox" asp-for="Model.Produtcs[i].Checked" />
#Model.Products[i].Number
#Model.Products[i].Name
}
}
This will render HTML like
<input type="checkbox" name="Products[0].Checked" />
<input type="checkbox" name="Products[1].Checked" />
<input type="checkbox" name="Products[2].Checked" />
And it should get back to your OnPostAsync. If not then try changing
public async Task OnPostAsync(List<Product> upload)
to
public async Task OnPostAsync(YourModel model)
What ever your full model is named.
This is then redundant:
#{
var items = Model.Products.Where(x => x.Checked);
}

ASP.Net MVC Posting Form

I've got these Models:
public class FinalizedWebinarAttendeesList
{
public List<FinalizedWebinar> Webinars { get; set; }
}
public class FinalizedWebinar
{
public int ParticipantID { get; set; }
public bool AffidavitRecvd { get; set; }
}
Now, I want to put this data into an HTML form for viewing and allow the user to set a checkbox for the AffidavitRecvd value and the ParticipantID for each attendee.
The form I have is an accordion in a panel group with each Attendance in a table shown in the HTML below.
<div class="row">
<form name="FinalizeWebinar" id="finalize-webinar-form" method="post" action="/Home/StoreFinalized">
<div class="col-lg-12" id="attendeesTable">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title pull-left" style="width:90%">
<a class="" data-toggle="collapse" data-parent="#accordion" href="#collapse0" aria-expanded="true">909428<br>Katie Perry</a>
<input type="hidden" name="[909428].ParticipantID" value="909428">
</h4>
<div class="pull-right" style="width:10%;">
<span class="affrcvd_chk">Affidavit Received?<br>
<input id="affrcvd_chk_box" type="checkbox" name="[0].AffidavitRecvd">
</span>
</div>
<div class="clearfix"></div>
</div> <!--/.panel-heading -->
<div id="collapse0" class="panel-collapse collapse in" aria-expanded="true">
<div class="panel-body">
<div>
<input type="hidden" name="[0].FullName" value="Katie Perry">
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped" id="attendee0Table">
<thead>
<tr>
<th>Webinar</th>
<th>Time In Session</th>
<th>First Poll Count</th>
<th>Second Poll Count</th>
<th>Attended</th>
</tr>
</thead>
<tbody>
<tr class="">
<td>Webinar 1: Wednesday</td>
<td>2 hrs 27 mins</td>
<td>4</td>
<td>4</td>
<td>YES</td>
</tr>
<tr class="">
<td>Webinar 1: Thursday</td>
<td>2 hrs 4 mins</td>
<td>4</td>
<td>4</td>
<td>YES</td>
</tr>
</tbody>
</table>
</div> <!-- /.table-responsive -->
</div>
</div> <!--/.panel-body -->
</div> <!--/.panel-collapse -->
</div><!-- /.panel -->
</div> <!-- /.panel-group -->
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title pull-left" style="width:90%">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse1">914251<br>Taylor Swift</a>
<input type="hidden" name="[914251].ParticipantID" value="914251">
</h4>
<div class="pull-right" style="width:10%;">
<span class="affrcvd_chk">Affidavit Received?<br>
<input id="affrcvd_chk_box" type="checkbox" name="[1].AffidavitRecvd">
</span>
</div>
<div class="clearfix"></div>
</div> <!--/.panel-heading -->
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">
<div>
<input type="hidden" name="[1].FullName" value="Taylor Swift">
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped" id="attendee1Table">
<thead>
<tr>
<th>Webinar</th>
<th>Time In Session</th>
<th>First Poll Count</th>
<th>Second Poll Count</th>
<th>Attended</th>
</tr>
</thead>
<tbody>
<tr class="">
<td>Webinar 1: Wednesday</td>
<td>2 hrs 37 mins</td>
<td>4</td>
<td>4</td>
<td>YES</td>
</tr>
<tr class="">
<td>Webinar 1: Thursday</td>
<td>2 hrs 11 mins</td>
<td>4</td>
<td>4</td>
<td>YES</td>
</tr>
</tbody>
</table>
</div><!-- /.table-responsive -->
</div>
</div><!--/.panel-body -->
</div><!--/.panel-collapse -->
</div><!-- /.panel -->
</div><!-- /.panel-group -->
</div> <!-- /.col-lg-12 -->
</form>
</div><!-- /.row -->
This is the definition for the function in the form's action:
public ActionResult StoreFinalized(List<FinalizedWebinar> attendees)
But when I post, the attendees parameter is null and this is what is sent in the postdata:
[909428].ParticipantID:909428
[909428].AffidavitRecvd:on
[914251].ParticipantID:914251
[914251].AffidavitRecvd:on
I've also tried this definition:
public ActionResult StoreFinalized(FinalizedWebinarAttendeesList attendees)
and the attendees.Webinars is null.
What am I doing wrong here?
Your view:
#using (Html.BeginForm("Index"))
{
<input type="text" name="Webinars[0].ParticipantID" value="1" />
<input type="text" name="Webinars[0].AffidavitRecvd" value="11" />
<input type="text" name="Webinars[1].ParticipantID" value="2" />
<input type="text" name="Webinars[1].AffidavitRecvd" value="22" />
<input type="submit" value="submit" />
}
Your controller:
[HttpPost]
public ActionResult Index(FinalizedWebinarAttendeesList form)
{
return View();
}
use the same viewmodel that you have described.

Categories