The RequesterIndex page should render the filenumber to hidden field. The post page should redirect back to the original page.
after make submit click button url change why and how to prevent that ?
Ahmed Abd El Aziz
315
Reputation points
I work on asp.net MVC razor page . I face issue Url change from
Resignation/RequesterIndex?filenumber=103085
to
Resignation/Create
after click submit button
so I need Url still as it is before without change after click submit button
my code details as below
@model HR.WorkforceRequisition.Models.ResignationRequester
@{
ViewBag.Title = "Requester Index";
Layout = "~/Views/Shared/_LayoutResignation.cshtml";
}
@using (Html.BeginForm("Create", "Resignation", FormMethod.Post, new { enctype = "multipart/form-data", @id = "ResignationForm", style = "padding-top: 50px" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@if (!string.IsNullOrEmpty(ViewBag.errorMsg))
{
<div class="alert alert-danger">
@ViewBag.errorMsg
</div>
}
@if (!string.IsNullOrEmpty(ViewBag.successMessage))
{
<div class="alert alert-success">
@ViewBag.successMessage
</div>
}
<div class="row">
<div class="form-group col-md-6 hover">
<div class="col-md-5">
@Html.LabelFor(model => model.EmpID, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7">
@Html.EditorFor(model => model.EmpID, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.EmpID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6 hover">
<div class="col-md-5">
@Html.LabelFor(model => model.EmpName, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7">
@Html.EditorFor(model => model.EmpName, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.EmpName, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6 hover">
<div class="col-md-5">
@Html.LabelFor(model => model.Dept, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7">
@Html.EditorFor(model => model.Dept, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.Dept, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6 hover">
<div class="col-md-5">
@Html.LabelFor(model => model.Designation, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7">
@Html.EditorFor(model => model.Designation, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.Designation, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6 hover">
<div class="col-md-5">
@Html.LabelFor(model => model.ResignationSubmissionDate, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7">
@Html.EditorFor(model => model.ResignationSubmissionDate, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.ResignationSubmissionDate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6 hover">
<div class="col-md-5">
@Html.LabelFor(model => model.MobileNo, htmlAttributes: new { @class = "control-label" })
<span class="text-danger"> *</span>
</div>
<div class="col-md-7">
@Html.EditorFor(model => model.MobileNo, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MobileNo, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-0 col-md-12">
<input type="submit" value="Submit" class="btn btn-success" />
</div>
</div>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
public ActionResult RequesterIndex(string filenumber) { return View(resignationRequester);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create(ResignationRequester resignationRequester)
{
if (Session[SessionKeys.UserCode] != null)
{
JDEUtility jde = new JDEUtility();
var propertiesWithErrors = ModelState.Where(x => x.Value.Errors.Any())
.Select(x => x.Key)
.ToList();
if (ModelState.IsValid)
{
int checkEmployeeNoExist = jde.CheckEmployeeExistOrNot(resignationRequester.EmpID);
if (checkEmployeeNoExist >= 1)
{
ViewBag.errorMsg = "Employee Exist Before";
goto InvalidModel;
}
try
{
Workforce.InsertToReignation(resignationRequester, (string)Session[SessionKeys.Username], (DateTime)Session[SessionKeys.LastWorkingDate], noticeperiod, (int)Session[SessionKeys.UserCode]);
}
catch (Exception ex)
{
ViewBag.errorMsg = "Create Not Done Correctly";
}
Session[SessionKeys.DirectManager] = GetEmployeeName(Convert.ToString(resignationRequester.DirectManager));
Session[SessionKeys.LineManager] = GetEmployeeName(Convert.ToString(resignationRequester.LineManager));
if (string.IsNullOrEmpty(ViewBag.errorMsg))
{
ViewBag.successMessage = "Resignation Submission form Created successfully";
}
}
else
{
var errors = ModelState.Select(x => x.Value.Errors)
.Where(y => y.Count > 0)
.ToList();
ViewBag.errorMsg = "Some Required Fields Not Added";
}
}
else
{
ViewBag.errorMsg = "No Data For This File No";
}
InvalidModel:
ViewBag.isPostBack = true;
return View(resignationRequester);
}
2 answers
Sort by: Most helpful
-
-
Andreo 0 Reputation points
2023-09-11T17:27:17.9966667+00:00 Could you maybe provide more information, such as an example of the code you mean?