I have this form which submit successfully, I insert the values of the name text box into the createdby column in the database and also the datepicker textbox.
since I submit the value of the name as the createdby value I need to hide the createdby textfield and also hide the datepicker textbox since I will like to use current date
what I want
1) hide the createdby textfield from the form
2) hide the LastLoggedDate datepicker and insert current date
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DLFeed100.Model
{
[Table("UserDetails")]
public class UserDetail
{
[Key]
public string UserID { get; set; }
public string Password { get; set; }
public string Name { get; set; }
public int MobNumber { get; set; }
public string EmailID { get; set; }
public string EmpID { get; set; }
public string RoleID { get; set; }
public string DesignID { get; set; }
public DateTime LastLoggedDate { get; set; }
public string CreatedBy { get; set; }
}
}
BUSINESS LAYER
using DLFeed100.Model;
using DLFeed100.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace BLFeed100
{
public class UserDetailDataManagement
{
UserDetailDataManagement objBL = new UserDetailDataManagement();
public string InsertUserDatail(UserDetail usr)
{
string msg = string.Empty;
try
{
// In case before passing the prod object to DL in line 40, you want to do any data manipulation
objBL.InsertUserDatail(usr);
msg = "success";
}
catch (Exception ex)
{
msg = "failed";
}
return msg;
}
}
}
ABSTRACT CLASS
using DLFeed100.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DLFeed100.Abstract
{
public interface IUserDetailManagement
{
UserDetail GetLogin(string userID, string password);
}
}
REPOSITORY
using DLFeed100.Abstract;
using DLFeed100.Model;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
namespace DLFeed100.Repository
{
public class UserDetailDataManagement : IUserDetailManagement
{
UserDetailDbContext _context = new UserDetailDbContext();
public string InsertUserDatail(UserDetail usr)
{
string msg = string.Empty;
try
{
_context.UserDetails.Add(usr);
_context.SaveChanges();
UserDetail updatedusr = usr;
updatedusr.CreatedBy = updatedusr.Name;
_context.SaveChanges();
msg = "success";
}
catch (Exception ex)
{
msg = "failed";
}
return msg;
}
}
}
CONTEXT DB
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DLFeed100.Model
{
public class UserDetailDbContext : DbContext
{
public DbSet<UserDetail> UserDetails { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer("Server=DESKTOP-1M2N4KR\\HQ;Database=Rocky;Integrated Security=true;Trusted_Connection=True;TrustServerCertificate=True;");
}
base.OnConfiguring(optionsBuilder);
}
}
}
CONTROLLER
using DLFeed100.Model;
using DLFeed100.Repository;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Cryptography;
using System.Text;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Feed100.Controllers
{
public class UserDetailController : Controller
{
//UserDetailDataManagement objBL = new UserDetailDataManagement();
UserDetailDataManagement objBL = new UserDetailDataManagement();
public ActionResult Index()
{
return View();
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(UserDetail usr)
{
if (ModelState.IsValid)
{
string msg = objBL.InsertUserDatail(usr);
if (msg == "success")
{
return RedirectToAction("index");
}
else
{
ViewBag.ErrorInfo = "Data not saved, try again latter";
}
}
return View();
}
}
}
CSHTML PAGE
@model DLFeedback360.Model.UserDetail
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Create</title>
</head>
<body>
<h4>UserDetail</h4>
<hr />
<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="UserID" class="control-label"></label>
<input asp-for="UserID" class="form-control" />
<span asp-validation-for="UserID" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Password" class="control-label"></label>
<input asp-for="Password" class="form-control" />
<span asp-validation-for="Password" 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">
<label asp-for="MobNumber" class="control-label"></label>
<input asp-for="MobNumber" class="form-control" />
<span asp-validation-for="MobNumber" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="EmailID" class="control-label"></label>
<input asp-for="EmailID" class="form-control" />
<span asp-validation-for="EmailID" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="EmpID" class="control-label"></label>
<input asp-for="EmpID" class="form-control" />
<span asp-validation-for="EmpID" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="RoleID" class="control-label"></label>
<input asp-for="RoleID" class="form-control" />
<span asp-validation-for="RoleID" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="DesignID" class="control-label"></label>
<input asp-for="DesignID" class="form-control" />
<span asp-validation-for="DesignID" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="LastLoggedDate" class="control-label"></label>
<input asp-for="LastLoggedDate" class="form-control" />
<span asp-validation-for="LastLoggedDate" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="SUBMIT" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>
</body>
</html>
PLEASE HELP
HOW TO HIDE TEXTFIELD IN A CSHTEML PAGE AND INSERT current INSTEAD OF A DATEPICKER TEXTBOX