DateTime destroys View - c#

I have a pretty basic/standard MVC project I'm building up. Everything in it works fine (Fig 1) until I add a DateTime object to my Model (Fig 2), at which point the View for that Model gets very distorted, and won't display any information (Fig 3). See the entry in my SQL Database for the related DateTime object (Fig 4).
I am left to assume it's something to do specifically with the DateTime data type, but I'm not sure What might be causing this or what could I try for troubleshooting.
Fig 1:
Fig 2:
Fig 3:
Fig 4:
Code from my View as asked:
#model TKOPOC.Models.SubmitEIDs
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
#* Model Update Alert *#
#if(Model.isVerify){ <h1><span style="color: red;">VERIFY YOUR CHANGES, THEN CLICK SUBMIT</span></h1> }
#*Search Box*#
#if(!Model.isVerify)
{
using (Html.BeginForm("Index", "EightID", FormMethod.Get))
{
<p>
Find by name or EID: #Html.TextBox("searchString", ViewBag.CurrentFilter as string)
<input type="submit" value="Search" />
</p>
}
<p>
#Html.ActionLink("Create New", "Create")
</p>
}
<table>
<tr>
<th>
#Html.ActionLink("EID", "Index", new { sortOrder=ViewBag.EIDSortParm, currentFilter=ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink("Name", "Index", new { sortOrder=ViewBag.NameSortParm, currentFilter=ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink("Email", "Index", new { sortOrder=ViewBag.EmailSortParm, currentFilter=ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink("Physical", "Index", new { sortOrder=ViewBag.PhysicalSortParm, currentFilter=ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink("Admin", "Index", new { sortOrder=ViewBag.AdminSortParm, currentFilter=ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink(" Maint", "Index", new { sortOrder=ViewBag.MaintSortParm, currentFilter=ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink(" Cab", "Index", new { sortOrder=ViewBag.CabSortParm, currentFilter=ViewBag.CurrentFilter })
</th>
<th>
#Html.ActionLink(" Mills", "Index", new { sortOrder=ViewBag.MillSortParam, currentFilter=ViewBag.CurrentFilter })
</th>
<th></th>
</tr>
#foreach (var item in Model.EightIDsPagedList) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.EID)
</td>
<td>
#Html.DisplayFor(modelItem => item.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.Email)
</td>
<td>
#Html.DisplayFor(modelItem => item.Physical)
</td>
<td>
#Html.DisplayFor(modelItem => item.Admin)
</td>
<td>
#Html.DisplayFor(modelItem => item.Maint)
</td>
<td>
#Html.DisplayFor(modelItem => item.Cab)
</td>
<td>
#if (item.Admin | item.Maint)
{
<text>All</text>
}
else
{
#Html.DisplayFor(modelItem => item.Mills.Count)
}
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id=item.EightIDID }) |
#Html.ActionLink("Details", "Details", new { id=item.EightIDID }) |
#Html.ActionLink("Delete", "Delete", new { id=item.EightIDID })
</td>
</tr>
}
</table>
<p>&nbsp</p>
#* Paging *#
<div>
Page #(Model.EightIDsPagedList.PageCount < Model.EightIDsPagedList.PageNumber ? 0 : Model.EightIDsPagedList.PageNumber)
of #Model.EightIDsPagedList.PageCount
#if (Model.EightIDsPagedList.HasPreviousPage)
{
#Html.ActionLink("<<", "Index", new { page = 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter })
#Html.Raw(" ");
#Html.ActionLink("< Prev", "Index", new { page = Model.EightIDsPagedList.PageNumber - 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter })
}
else
{
#:<<
#Html.Raw(" ");
#:< Prev
}
#for (var x = 1; x < Model.EightIDsPagedList.PageCount; x++)
{
if (Model.EightIDsPagedList.PageNumber == x)
{
#x;
}
else
{
#Html.ActionLink(Convert.ToString(x), "Index", new { page = x, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter });
}
}
#if (Model.EightIDsPagedList.HasNextPage)
{
#Html.ActionLink("Next >", "Index", new { page = Model.EightIDsPagedList.PageNumber + 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter })
#Html.Raw(" ");
#Html.ActionLink(">>", "Index", new { page = Model.EightIDsPagedList.PageCount, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter })
}
else
{
#:Next >
#Html.Raw(" ")
#:>>
}
</div>
<p>&nbsp</p>
<table border="0">
<tr>
#if (!Model.isVerify)
{
using (Html.BeginForm("Index", "EightID", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<td>
<input type="file" name="file" required />
<input type="submit" name="Verify" value="Verify" />
</td>
}
}
else
{
using (Html.BeginForm("Submit", "EightID", FormMethod.Post, new { NewEIDs = Model.EightIDs }))
{
<td>
<input type="submit" name="Submit Changes" value="Submit" />
</td>
}
using (Html.BeginForm("Cancel", "EightID", FormMethod.Post))
{
<td>
<input type="submit" name="Cancel" value="Cancel" />
</td>
}
}
</td>
</tr>
</table>
Edit:
After some more debugging through the view, I've found where the issue occurs, just not why - after the table headers, we come down to the foreach() loop where the DisplayFor happens. Here, the program hits foreach. Then Model.EightIDsPagedList. Then "in". But then it never comes into var or item and just skips the loop entirely. When I removed the DateTime items in question, the program enters the loop as you would expect it to and continues execution all the way down.

Do you get a null reference exception anywhere? Do you have a value in the DateTime column when you run the example? Your SQL seems to be nullable but your property is not. You could try these options:
Making that a DateTime? (nullable DateTime) in the code.
Make sure you have a value in SQL
Making the SQL column not nullable (which will guarantee option 2).
Let us know if that helps.

Related

why Html.checkboxfor is not sends or changes the boolean value of the model?

I have a simple project that allows the customer to select multiple users and remove them from the DataBase. But the check boxes are not change or sent the isSelected variable which is tells the server that which users are have to be removed.
Client Side:
#model IEnumerable<WebApplication1.Models.User>
#{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
#{
int i;
}
<h2><strong>جدول</strong></h2>
#using (Html.BeginForm())
{
<p>
#Html.ActionLink("اضافه کردن کاربر", "Create"
, null, new { #class = "btn btn-success", #id = "btnCreate" })
<input type="submit" class="btn btn-danger hidden" id="btnMultipleDelete" value="حذف کاربران" />
</p>
<table class="table" border="0" style="user-select: none;">
<tr>
<th>
<strong>نام</strong>
</th>
<th>
<strong>نام خانوادگی</strong>
</th>
<th>
<strong>سنّ</strong>
</th>
<th></th>
</tr>
#for(i = 0; i < Model.Count(); i++)
{
<tr class="mainList" id="tr-#i"
onmouseover="changeCurrentRow(this.id), mouseIn(true)"
onmouseout="clearCurrentRow(), mouseIn(false)">
<td class="IndexInfo">
<span class="IndexText">
#Html.DisplayFor(modelItem => modelItem.ToList()[i].User_FirstName)
</span>
</td>
<td class="IndexInfo">
<span class="IndexText">
#Html.DisplayFor(modelItem => modelItem.ToList()[i].User_LastName)
</span>
</td>
<td class="IndexInfo">
<span class="IndexText persianNumber">
#Html.DisplayFor(modelItem => modelItem.ToList()[i].User_Age)
</span>
</td>
<td align="center" style="flex:3">
#Html.ActionLink("ویرایش", "Edit", new { id = Model.ToList()[i].User_Id },
new { #class = "btn btn-primary", #id = "btnEdit-" + i })
#Html.ActionLink("مشاهده", "Details", new { id = Model.ToList()[i].User_Id },
new { #class = "btn btn-secondary", #id = "btnDetail-" + i })
#Html.ActionLink("حذف", "Delete", new { id = Model.ToList()[i].User_Id },
new { #class = "btn btn-warning", #id = "btnDelete-" + i })
#Html.HiddenFor(u => u.ToList()[i].User_Id)
#Html.HiddenFor(u => u.ToList()[i].User_FirstName)
#Html.HiddenFor(u => u.ToList()[i].User_LastName)
#Html.HiddenFor(u => u.ToList()[i].User_Age)
#Html.CheckBoxFor(u => u.ToList()[i].IsSelected, new { #class = "", #id = "cb-" + i })
</td>
</tr>
}
</table>
}
Server Side:
[HttpPost]
public ActionResult Index(IEnumerable<User> users)
{
if (users.Count() == 0)
{
return RedirectToAction("Index");
}
else
{
User user;
foreach (User u in users)
{
if (u.IsSelected)
{
user = db.Users.ToList().Find(x => x.User_Id == u.User_Id);
db.Users.Remove(user);
}
}
db.SaveChanges();
return RedirectToAction("Index");
}
}
notice that i have tried to put a hidden input for isSelected Variable But that still doesn't work
so, while no one cares about my question i found the solution by my self.
Controller can not receive the IsSelected property from the View because i have changed the identity of the checkbox like id,name and ...
that means if i dont change the the identities of the checkbox, the code will works but even this solution leads us to another problem that you no longer can find the checkbox by JS. so i dont give this answer green tick until someone finds a better way to fix it.
for this solution something that you have to do is change the check box code from this:
#Html.CheckBoxFor(u => u.ToList()[i].IsSelected, new { #class = "", #id = "cb-" + i })
to this:
#Html.CheckBoxFor(u => u.ToList()[i].IsSelected})
and it basically will works.

Local variable in MVC View

I have an MVC view that displays a list of items. The table that was automatically generated with the view has this action link on every row:
#Html.ActionLink("Delete", "Delete", new { id = item.section_detail_id }).
This works fine but my requirement is to allow the user to highlight a row and click on a delete button at the bottom of the list. I need a way for the button to know which row is currently highlighted. So I created this local variable:
#{int sectionDetailId = 0; }
Then I added an onclick event on the table rows to store the the id of the row that is clicked:
tr id="#item.section_detail_id" onclick="addClass(this.id); sectionDetailId = #item.section_detail_id">
Here is the button that is supposed to bring up the delete view:
input type="button" value="Delete Employee" onclick="location.href='#Url.Action("Delete", "EmployeeList", new { id = sectionDetailId })'; alert(sectionDetailId)" />
The value that is passed to the view is always zero no matter what row is clicked. I added the alert function to the button to show that the variable has the correct value.
Is there a way to get the Action method to use the variable or to get the value from the table in some other way? The Action method works correctly if I hard code an ID.
Here is the complete view:
#model IEnumerable<VCPDS2.Models.EmployeeListViewModel>
#{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<style>
tr.highlight {
background-color: blue !important;
}
</style>
#{int sectionDetailId = 0; }
<h2>Index</h2>
#*<p>
#Html.ActionLink("Create New", "Create")
</p>*#
#if (Model != null)
{
<table id="employeeTable" class="table table-responsive table-striped">
<tr>
<th>
Last Name
</th>
<th>
First Name
</th>
<th>
Employee ID
</th>
<th>
Phone
</th>
<th>
Budget Unit
</th>
<th>
Division
</th>
</tr>
<tbody id="employeeList">
#foreach (var item in Model)
{
<tr id="#item.section_detail_id" onclick="addClass(this.id); sectionDetailId = #item.section_detail_id">
<td>
#Html.DisplayFor(modelItem => item.last_name)
</td>
<td>
#Html.DisplayFor(modelItem => item.first_name)
</td>
<td>
#Html.DisplayFor(modelItem => item.employee_id)
</td>
<td>
#item.phone_nbr
#* #Html.DisplayFor(modelItem => item.phone.area_code) #Html.DisplayFor(modelItem => item.phone.phone_nbr)*#
</td>
<td>
#item.BU
#*#Html.DisplayFor(modelItem => item.phone.BU)*#
</td>
<td>
#item.description
#*#Html.DisplayFor(modelItem => item.department.description)*#
</td>
<td>
#*#Html.ActionLink("Edit", "Edit", new { id = item.section_detail_id }) |
#Html.ActionLink("Details", "Details", new { id = item.section_detail_id }) |*#
#Html.ActionLink("Delete", "Delete", new { id = item.section_detail_id })
</td>
</tr>
}
</tbody>
</table>
<p>
#*#Html.ActionLink("Create New", "Create")*#
<input type="button" value="Add Employee"
onclick="location.href='#Url.Action("Create", "EmployeeList")'" />
<input type="button" value="Delete Employee"
onclick="location.href='#Url.Action("Delete", "EmployeeList", new { id =
#sectionDetailId })'; alert(sectionDetailId)" />
</p>
}
<script src="jquery-3.4.1.min.js"></script>
<script>
function addClass(row) {
//alert(row);
$('#employeeList').children().removeClass('highlight');
var element = document.getElementById(row);
element.classList.add("highlight");
}
</script>
#*#Html.ActionLink("Edit", "Edit", new { id = item.section_detail_id }) |
#Html.ActionLink("Details", "Details", new { id = item.section_detail_id }) |
#Html.ActionLink("Delete", "Delete", new { id = item.section_detail_id
})*#
This is the rendered HTML for the delete button:
<input type="button" value="Delete Employee" onclick="location.href='/EmployeeList/Delete/0'; alert(sectionDetailId)">

Why are the parameters of my action null?

I'm trying to make a page using ASP MVC 5 with C# in which I have some controls to type search parameters and a table where the results are shown.
The thing is that the user should be allowed to edit the text of two fields in the table and save the changes.
To accomplish this, my view receives a model with two objects as properties, one for the search parameters and one for the result list, like this:
public class SEARCH_PAGE
{
public List<VIEW_DATA_APR> table{ get; set; }
public SEARCH parameters{ get; set; }
}
Then my Controller is this:
public class CargaAPRController : Controller
{
private datasource db = new datasource();
// GET: CargaAPR
public ActionResult Index()
{
try
{
List<SelectListItem> items = new SelectList(db.COMPANY, "IDCOMPANY", "COMPANYNAME").ToList();
items.Insert(0, (new SelectListItem { Text = "ALL", Value = "0" }));
ViewData["IDCOMPANY"] = items;
var letters = (from c in db.LETTERS
select new VIEW_DATA_APR
{
company = c.COMPANY.COMPANYNAME,
idLetter = c.IDLETTER,
nic = "not found",
client = "not found",
energy = 0,
money = 0,
period = "",
letterCode = c.LETTERCODE
});
SEARCH_PAGE sp = new SEARCH_PAGE();
sp.table= letters.ToList();
sp.parameters= new SEARCH();
return View(sp);
}
catch (Exception ex)
{
return RedirectToAction("Error", new RouteValueDictionary(new { controller = "Users", action = "Error", mensaje = "Error: " + ex.Message }));
}
}
[HttpPost]
public ActionResult Index(SEARCH_PAGE model)
{
try
{
List<SelectListItem> items = new SelectList(db.COMPANY, "IDCOMPANY", "COMPANYNAME").ToList();
items.Insert(0, (new SelectListItem { Text = "ALL", Value = "0" }));
ViewData["IDCOMPANY"] = items;
decimal company = Decimal.Parse(model.parameters.company);
var letters= (from c in db.LETTERS
where (company== 0 ? c.IDCOMPANY: company) == c.IDCOMPANY
select new VIEW_DATA_APR
{
company= c.COMPANY.COMPANYNAME,
idLetter= c.IDLETTER,
nic = "not found",
client = "not found",
energy = 0,
money = 0,
period = "",
letterCode = c.LETTERCODE
});
SEARCH_PAGE sp = new SEARCH_PAGE();
sp.table= letters.ToList();
sp.parameters = model.parameters;
return View(sp);
}
catch (Exception ex)
{
return RedirectToAction("Error", new RouteValueDictionary(new { controller = "Users", action = "Error", mensaje = "Error: " + ex.Message }));
}
}
[HttpPost]
public ActionResult Save(SEARCH_PAGE model_search_page )
{
return View();
}
}
And my View is:
#using datasource.Models
#model SEARCH_PAGE
#{
ViewBag.Title = "Load APR";
Layout = "~/Views/Shared/_Layout.cshtml";
}
#Styles.Render("~/Content/energetica.css")
<meta name="viewport" content="width=device-width" />
<title>Letters</title>
<link href="#Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<div class="container-fluid">
<div class="col-md-1">
</div>
<div class="col-md-10">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">
<div class="row">
<div class="col-md-1">
<a href="#Url.Action("Index", "LoadFiles")" class="elements">
<img class="img img-responsive" style="width:25px; height:26px;padding:1px" src="~/img/BackIcon.png">
</a>
</div>
<div class="col-md-11 text-left" style="padding:1px;">
LOAD APR
</div>
</div>
</div>
</div>
#using (Html.BeginForm("Index","LoadAPR", FormMethod.Post, null))
{
<table style="width:100%">
<tr>
<td style="width:10%">
<b>COMPANY: </b>
</td>
<td style="width:20%">
#Html.DropDownListFor(m => m.parameters.company, (IEnumerable<SelectListItem>)ViewData["IDCOMPANY"], new { htmlAttributes = new { #class = "form-control" } })
</td>
<td style="width:10%">
<b>PERIOD: </b>
</td>
<td style="width:20%">
#Html.EditorFor(m => m.parameters.period)
</td>
<td style="width:20%; text-align:right">
<input type="submit" name="SEARCH" value="SEARCH" />
</td>
</tr>
<tr>
<td style="width:10%">
<b>CLIENT: </b>
</td>
<td style="width:20%">
#Html.EditorFor(m => m.parameters.client)
</td>
<td style="width:10%">
<b>NIC: </b>
</td>
<td style="width:20%">
#Html.EditorFor(m => m.parameters.nic)
</td>
</tr>
</table>
}
<br />
#using (Html.BeginForm("Save", "LoadAPR", FormMethod.Post, null))
{
<div style="overflow-y: scroll; max-height: 300px">
<table style="width:100%">
<tr>
<th>
#Html.Label("LBDIS", "Company")
</th>
<th>
#Html.Label("LBNLETTER", "Letter Code")
</th>
<th>
#Html.Label("LBNIC", "NIC")
</th>
<th>
#Html.Label("LBCLIENT", "Client")
</th>
<th>
#Html.Label("LBENERGY", "Energy")
</th>
<th>
#Html.Label("LBMONEY", "Money")
</th>
</tr>
#foreach (var item in Model.table)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.company)
</td>
<td>
#Html.DisplayFor(modelItem => item.letterCode)
</td>
<td>
#Html.DisplayFor(modelItem => item.nic)
</td>
<td>
#Html.DisplayFor(modelItem => item.client)
</td>
<td>
#Html.EditorFor(modelItem => item.energy)
</td>
<td>
#Html.EditorFor(modelItem => item.money)
</td>
</tr>
}
</table>
</div>
<br />
<div style="width:100%; text-align:right;">
<input class="btn-addUser" type="submit" value="Save" />
</div>
}
</div>
So when I run it and click on my first button, the POST Index parameter receives just the parameters part of the object, the table part is null
And when I click on my second button, the POST Save parameter comes null in both properties.
I have tried so many different ways of seding the Model as parameter but nothing is working. Could you tell me what's wrong? Am I using he BeginForm in the correct way?
Thank you in advance.

MVC replacing Edit/Details/Delete with Icons

I want to replace those three fields Edit/Details/Delete with icons I just downloaded. The icons are with size 512x512, will this be a problem? Can I resize them in the code (how), or I should resize them using some program.
I've been searching through the net and I found some very long pieces of C# code but I have no idea where to put it in order to replace the text of those properties with the icons.
Here is my HTML:
#using PagedList.Mvc;
#model PagedList.IPagedList<Rating_System.Models.tblTeacher>
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
#{
ViewBag.Title = "Teachers List";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Teachers</h2>
<p>
#Html.ActionLink("Add new", "Create")
</p>
#using (Html.BeginForm("Index", "Teachers", FormMethod.Get))
{
<p>
Търсене: #Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
<input type="submit" value="Search" />
</p>
}
<table class="table">
<tr>
<th>
</th>
<th>
#Html.DisplayNameFor(model => model.First().FirstName)
</th>
<th>
#Html.DisplayNameFor(model => model.First().SecondName)
</th>
<th>
#Html.DisplayNameFor(model => model.First().Title)
</th>
<th></th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
<img src="#Url.Action("GetImage", "Teachers", new {item.ID})" width="45" height="45" />
</td>
<td>
#Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
#Html.DisplayFor(modelItem => item.SecondName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Title)
</td>
<td>
#Html.ActionLink("Редактирай", "Edit", new { id = item.ID }) |
#Html.ActionLink("Детайли", "Details", new { id = item.ID }) |
#Html.ActionLink("Изтрий", "Delete", new { id = item.ID })
</td>
</tr>
}
</table>
#Html.PagedListPager(Model, page => Url.Action("Index", new { page, pageSize = Model.PageSize }))
Results #Model.FirstItemOnPage - #Model.LastItemOnPage от общо #Model.TotalItemCount Teachers
try with this code
<a href="#Url.Action("ActionName", "ControllerName", new { id = item.ID })">
<img src="#Url.Content("~/Content/imgname.jpg")" />
</a>
If you want to use an icon (Image) use the following code:
#Html.ActionLink("Редактирай", "Edit", new { id = item.ID }, new { #class="class" })
Then write you css class to include a background image
a.class
{
background: url(../Images/image.gif) no-repeat top left;
width: 50px;
height: 50px;
display: block;
text-indent: -9999px; /* hides the link text */
}
However, I would suggest using bootstrap glyphicons for example
<a href="#Url.Action("Action", "Controller")" class="btn btn-info">
Your link text
<span class="glyphicon glyphicon-time" aria-hidden="true"></span>
</a>
Or
<span class="glyphicon glyphicon-ok" style="cursor:pointer" onclick="JavascriptFunction()"></span>
And in Javascript
function JavascriptFunction() {
window.location.href = encodeURI("/Controller/Action/");
}
You can pass the ID through the javascript function

Why my button in MVC doesn't work?

I've got this code:
#model IEnumerable<PamelaFundacionFinal.Models.Escuela>
#{
ViewBag.Title = "Index";
}
<h2>Escuelas registradas</h2>
<p>
<button name="Edit" class="btn btn-default"><b>
#Html.ActionLink("Create New", "Create")</b></button></p>
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.Nombre)
</th>
<th>
#Html.DisplayNameFor(model => model.Direccion)
</th>
<th>
#Html.DisplayNameFor(model => model.Telefono)
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.Nombre)
</td>
<td>
#Html.DisplayFor(modelItem => item.Direccion)
</td>
<td>
#Html.DisplayFor(modelItem => item.Telefono)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id = item.Escuela_ID })
<button name="Edit" class="btn btn-default">
#Html.ActionLink("Details", "Details", new { id = item.Escuela_ID })</button>
<button name="Edit" class="btn btn-default">
#Html.ActionLink("Delete", "Delete", new { id = item.Escuela_ID })</button>
</td>
</tr>
}
</table>
Don't worry, everything is referenced to their own controller to make the opperations, my issue is that I've got two cases:
I'm writing in #Html.ActionLink("Edit", "Edit", new { id = item.Escuela_ID }) a reference to another controller, so I can create a new one, but it's simple text
Then, I'm trying to put that reference into a button, so it looks nice: <button name="Edit" class="btn btn-default">#Html.ActionLink("Delete", "Delete", new { id = item.Escuela_ID })</button> but it doesn't work.
I know that I'm not writing this correctly, but I need help because I'm new with this language and I don't really know exactly how is the syntax. I'm using Visual Studio 2013 and SQL Server to run the database (The connection with database is running perfectly, it's not an issue with the database).
You can style your <a> tag that is generated by the Html helper.
#Html.ActionLink("Edit", "Edit", new { id = item.Escuela_ID },
new { #class = "btn btn-default" })

Categories