wenqing wang

wenqing wang

  • NA
  • 4
  • 553

My submit button is not working

Jan 21 2020 10:44 PM
My cshtml
 
@model Performance;
@section MoreScripts {
<link href="~/lib/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
<script src="~/lib/moment/moment.min.js"></script>
<link href="~/lib/dtpicker/css/tempusdominus-bootstrap-4.min.css" rel="stylesheet" />
<script src="~/lib/dtpicker/js/tempusdominus-bootstrap-4.min.js"></script>
<script language="javascript">
$(document).ready(function () {
$('#JSPerformDT')
.datetimepicker({
format: 'YYYY-MM-DD HH:mm',
defaultDate: '@DateTime.Today.AddDays(14).ToString("yyyy-MM-dd")',
sideBySide: true
});
});
</script>
}
<form asp-controller="Performance"
asp-action="Create"
method="post">
<div class="form-group row">
<div class="offset-sm-2 col-sm-6 ">
<h2>Create Close Date</h2>
</div>
</div>
<div class="form-group row">
<label class="control-label col-sm-2" asp-for="Day">Day :</label>
<div class="col-sm-5">
<input asp-for="Day" class="form-control" />
</div>
<div class="col-sm-4">
<span asp-validation-for="Day" class="text-danger"></span>
</div>
</div>
<div class="form-group row">
<label class="control-label col-sm-2" asp-for="Description">Description :</label>
<div class="col-sm-5">
<input asp-for="Description" class="form-control" />
</div>
<div class="col-sm-4">
<span asp-validation-for="Description" class="text-danger"></span>
</div>
</div>
<div class="form-group row">
<label class="control-label col-sm-2" asp-for="CloseDT">Date :</label>
<div class="col-sm-5">
<div class="input-group date" id="JSPerformDT" data-target-input="nearest">
<input type="text" asp-for="CloseDT" class="form-control" />
<div class="input-group-append" data-target="#JSPerformDT" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
<div class="col-sm-4">
<span asp-validation-for="CloseDT" class="text-danger"></span>
</div>
</div>
<div class="form-group row">
<div class="offset-sm-2 col-sm-6">
<input type="submit" value="Sumbit" class="btn btn-primary" />
</div>
</div>
@if (ViewData["Message"] != null)
{
<div class="form-group row">
<div class="offset-sm-2 col-sm-6">
<div class="alert alert-@ViewData["MsgType"]">
@ViewData["Message"]
</div>
</div>
</div>
}
</form>
 
my controller 
 
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using FYP.Models;
using System;
using System.Collections.Generic;
using System.Data;
namespace FYP.Controllers
{
public class PerformanceController : Controller
{
[AllowAnonymous]
public IActionResult About()
{
return View();
}
[Authorize(Roles = "manager, member")]
public IActionResult Index()
{
DataTable dt = DBUtl.GetTable("SELECT * FROM Performance");
return View("Index", dt.Rows);
}
[Authorize(Roles = "manager")]
public IActionResult Create()
{
return View();
}
[Authorize(Roles = "manager")]
[HttpPost]
public IActionResult Create(Performance perform)
{
if (!ModelState.IsValid)
{
ViewData["Message"] = "Invalid Input";
ViewData["MsgType"] = "warning";
return View("Create");
}
else
{
string insert =
@"INSERT INTO Performance(Day, Description, CloseDT) VALUES
('{0}', '{1}', '{2:yyyy-MM-dd HH:mm}')";
int res = DBUtl.ExecSQL(insert, perform.Day, perform.Description, perform.CloseDT);
if (res == 1)
{
TempData["Message"] = "Date Created";
TempData["MsgType"] = "success";
}
else
{
TempData["Message"] = DBUtl.DB_Message;
TempData["MsgType"] = "danger";
}
return RedirectToAction("Index");
}
}
[Authorize(Roles = "manager")]
[HttpGet]
public IActionResult Update(int id)
{
string select = "SELECT * FROM Performance WHERE Did={0}";
List<Performance> list = DBUtl.GetList<Performance>(select, id);
if (list.Count == 1)
{
return View(list[0]);
}
else
{
TempData["Message"] = "Performance record does not exist";
TempData["MsgType"] = "warning";
return RedirectToAction("Index");
}
}
[Authorize(Roles = "manager")]
[HttpPost]
public IActionResult Update(Performance perform)
{
if (!ModelState.IsValid)
{
ViewData["Message"] = "Invalid Input";
ViewData["MsgType"] = "warning";
return View("Index");
}
else
{
string update = @"UPDATE Performance SET Day='{1}', Description='{2}', CloseDT='{3: yyyy-MM-dd HH:mm}' WHERE Did={0}";
int res = DBUtl.ExecSQL(update, perform.Did, perform.Day, perform.Description, perform.CloseDT);
if (res == 1)
{
TempData["Message"] = "Date Updated";
TempData["MsgType"] = "success";
}
else
{
TempData["Message"] = DBUtl.DB_Message;
TempData["MsgType"] = "danger";
}
return RedirectToAction("Index");
}
}
[Authorize(Roles = "manager")]
public IActionResult Delete(int id)
{
string select = @"SELECT * FROM Performance WHERE Did={0}";
DataTable ds = DBUtl.GetTable(select, id);
if (ds.Rows.Count != 1)
{
TempData["Message"] = "Performance does not exist";
TempData["MsgType"] = "warning";
}
else
{
string delete = "DELETE FROM Performance WHERE Did={0}";
int res = DBUtl.ExecSQL(delete, id);
if (res == 1)
{
TempData["Message"] = "Performance Deleted";
TempData["MsgType"] = "success";
}
else
{
TempData["Message"] = DBUtl.DB_Message;
TempData["MsgType"] = "danger";
}
}
return RedirectToAction("Index");
}
 
 

Answers (1)