When you generate MVC5 application you have in the controller 2 create action like the following
// GET: Roles/Create
public ActionResult Create()
{
return View();
}
and this which is the actual action for post
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,name,checkBox1,checkBox2,checkBox3")] Role role)
{
if (ModelState.IsValid)
{
db.Roles.Add(role);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(role);
}
I want to call to the second when I press on click from the index view, how should I do that? I try to put this code in the index view which is the button save from the create view but its not working. Any idea?
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
Update
Currently I put the button on element like this (at the end of string this is the create button but I see it on the UI but when I click on it noting happen
var html = '<tr><td>@Html.TextBox("Name")</td><td>@Html.CheckBox("checkBox1")</td><td></td><td><input type="submit" value="Create" class="btn bt
This is my all view code
<script src="../../Scripts/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function () {
//Append new row
var html = '<tr><td>@Html.TextBox("name")</td><td>@Html.CheckBox("checkBox1")</td><td>@Html.CheckBox("checkBox2")</td><td>@Html.CheckBox("checkBox3")</td><td><input id="btnsubmit" type="submit" value="Create" class="btn btn-default" /></td><td></tr>';
</script>
<input type="button" value="Add Row" onclick="addRow()" class="data-button" id="add-row" />
<table class="table" >
<tr>
<th>
@Html.DisplayNameFor(model => model.name)
</th>
<th>
@Html.DisplayNameFor(model => model.checkBox1)
</th>
<th>
@Html.DisplayNameFor(model => model.checkBox2)
</th>
<th>
@Html.DisplayNameFor(model => model.checkBox3)
</th>
<th></th>
</tr>
<tbody id="data-table">
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.name)
</td>
<td>
@Html.DisplayFor(modelItem => item.checkBox1)
</td>
<td>
@Html.DisplayFor(modelItem => item.checkBox2)
</td>
<td>
@Html.DisplayFor(modelItem => item.checkBox3)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>
}
</tbody>
</table>