ASP.NET MVC renders only the custom control - asp.net-mvc

I have been fighting this issue for over a week now and 20 developers can't figure out what is going on. I'm hoping someone here have seen this issue before.
Disclaimer: The website is a government site and it's password protected in a secured network, so unfortunately, I can't provide a link. But I'll try my best to explain as much as possible. If there is any particular code you want, I can provide it. I just don't want to clutter this question with a lot of useless code. SO here it goes.
Environment: ASP.NET MVC
Controls: Kendo Telerik
Architecture: Layout > Views > Partial Views
The screen in question is the search result screen. When the application runs, it inherits a _SharedLayout. Inside this Layout (Master Page) is where the views are. In this case, the Search.vbhtml View. Up to this point, the page has no issues. The problem happens when I enter information in the search boxes and run the search button. The View connects to the database, and it returns the data but the _SharedLayout and Search View do not render. After inspecting the browser, I noticed the following
<html>
<head> NOTHING HERE</head>
<body>
WHERE IS THE REST OF THE PAGE? LAYOUT AND SEARCH VIEW
<div>
Search result control forms and tables and all the good stuff
</div>
FOOTER IS MISSING TOO
</body>
</html>
And of course, without any references in the head of the page, the search results view is outputting styleless (as vanilla as it gets)
Here is the code for the search view (where the button that generates the results resides). Like I said above, if you need the controller code or anything else I'll do my best to provide it
#Modeltype IndividualSearchViewModel
#Code
Layout = Nothing
ViewData("Title") = "Search Individual"
ViewData("PageName") = "Search Individual"
Dim isPopupMode As String = "N"
Dim ajaxAction = New AjaxOptions With {.HttpMethod = "post", .UpdateTargetId = "IndividualSearchContent", .InsertionMode = InsertionMode.Replace}
If Not Model.Mode Is Nothing AndAlso Model.Mode.Equals("popup", StringComparison.CurrentCultureIgnoreCase) Then
isPopupMode = "Y"
ajaxAction.OnBegin = "OnPopupRequestBegin('IndividualSearchContent')"
ajaxAction.OnComplete = "OnPopupRequestComplete('IndividualSearchContent')"
Else
ajaxAction.OnBegin = "OnPageRequestBegin"
ajaxAction.OnComplete = "OnPageRequestComplete"
End If
End Code
<div id="IndividualSearchContent">
#Using Ajax.BeginForm("Index", "IndividualSearch", ajaxAction, New With {.role = "form"})
#<div class="searchCriteriaDivCss #(If(isPopupMode = "Y", "hidden", ""))">
#Html.ValidationSummary(False, "", New With {.class = "text-danger"})
</div>
#<div class="form-horizontal">
#If Model.Messages IsNot Nothing Then
#<div id="ValidationMessages" class="form-group text-center">
#For Each message In Model.Messages
#<b>#message</b>
#<br />
Next
</div>
#<br />
End If
<div class="row">
<div class="col-xs-12">
<div class="form-group">
#Html.LabelFor(Function(m) m.IdentifierType, New With {.class = "col-md-3 col-sm-12 col-xs-12"})
<div class="col-md-3 col-sm-12 col-xs-12">
#Html.Kendo.DropDownListFor(Function(m) m.IdentifierTypeValue).HtmlAttributes(New With {.class = "form-control"}).BindTo(Model.IdentifierType).OptionLabel("Select One")
</div>
#Html.LabelFor(Function(m) m.Identifier, New With {.class = "col-md-3 col-sm-12 col-xs-12"})
<div class="col-md-3 col-sm-12 col-xs-12">
#Html.Kendo.MaskedTextBoxFor(Function(m) m.Identifier).Mask("#########").HtmlAttributes(New With {.class = "form-control"})
</div>
</div>
<div class="form-group">
#Html.LabelFor(Function(m) m.LastName, New With {.class = "col-md-3 col-sm-12 col-xs-12"})
<div class="col-md-3 col-sm-12 col-xs-12">
#Html.TextBoxFor(Function(m) m.LastName, htmlAttributes:=New With {Key .maxlength = "50", .class = "form-control"})
</div>
#Html.LabelFor(Function(m) m.FirstName, New With {.class = "col-md-3 col-sm-12 col-xs-12"})
<div class="col-md-3 col-sm-12 col-xs-12">
#Html.TextBoxFor(Function(m) m.FirstName, htmlAttributes:=New With {Key .maxlength = "50", .class = "form-control"})
</div>
</div>
<div class="form-group">
#Html.LabelFor(Function(m) m.IndividualDOB, New With {.class = "col-md-3 col-sm-12 col-xs-12"})
<div class="col-md-3 col-sm-12 col-xs-12">
#Html.Kendo.DatePickerFor(Function(m) m.IndividualDOB).Max(Date.Today).HtmlAttributes(New With {.class = "form-control", .maxlength = "10"})
</div>
#Html.Label("Residential County:", New With {.class = "col-md-3 col-sm-12 col-xs-12"})
<div class="col-md-3 col-sm-12 col-xs-12">
#Html.Kendo.DropDownListFor(Function(m) m.ResidentialCounty).BindTo(Model.ResidentialCountyOptions).OptionLabel("Select One").HtmlAttributes(New With {.class = "form-control"})
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 text-center submitButtons">
#Html.Kendo.Button().Name("Clear").Content("Clear <i class='fa fa-times'></i>").HtmlAttributes(New With {.type = "submit", .name = "SubmitAction", .id = "clear", .value = "clear", .class = "btn-primary"})
#Html.Kendo.Button().Name("Search").Content("Search <i class='fa fa-search'></i>").HtmlAttributes(New With {.type = "submit", .name = "SubmitAction", .id = "search", .value = "search", .class = "btn-green"})
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="form-group text-center">
</div>
</div>
</div>
#If Model.SearchResults Is Nothing Then
#<div class="row">
<div class="col-xs-12">
<div class="form-group text-center complaintDetailButtons">
#Html.Kendo.Button().Name("NoIndividual").Content("<span>Continue Without Selecting<br> an Individual</span> <i class='fa fa-arrow-right'></i>").HtmlAttributes(New With {.id = "btnNoIndividual", .class = "btn btn-primary btn-xl long-wrap", .value = "noindividual"})
</div>
</div>
</div>
End If
#If (Model.SearchResults Is Nothing OrElse Model.SearchResults.Count = 0) AndAlso (Model.ProgramOffices IsNot Nothing AndAlso Model.ProgramOffices.Contains(EIM.BO.Enumerators.ProgramOffice.ODP)) AndAlso (Model.IsLicensed) Then
#<div class="row">
<div class="col-xs-12">
#Html.Kendo.Button().Name("NoMCI").ImageUrl(Url.Content("~/Content/Images/buttons/noMCI.jpg")).HtmlAttributes(New With {.id = "btnNoMCI", .value = "nomci"})
</div>
</div>
End If
#If Not Model.SearchResults Is Nothing AndAlso Model.SearchResults.Count > 0 Then
#<div class="row" id="resultsGrid">
<div class="col-xs-12">
#(Html.Kendo.Grid(Of IndividualSearchResultViewModel)(Model.SearchResults).
Name("SearchIndivResults").
Sortable(Function(s) s.AllowUnsort(False)).
Filterable().
Scrollable(Sub(s) s.Height("100%")).
Columns(Sub(c)
c.Bound(Function(m) m.MCI).ClientTemplate("<a href='' class='MCILink' id='#:MCI#_#:IndividualResultId#_#:ProgramOffice#'>#=MCI#</a>")
c.Bound(Function(m) m.SSN)
c.Bound(Function(m) m.Name).HtmlAttributes(New With {.class = "MCIName"})
c.Bound(Function(m) m.DOB)
c.Bound(Function(m) m.ResidentialCounty)
c.Bound(Function(m) m.ProgramOffice)
c.Bound(Function(m) m.WaiverName)
c.Bound(Function(m) m.ProgramEffectiveDates)
c.Bound(Function(m) m.SourceSystem).Hidden()
c.Bound(Function(m) m.Line1).Hidden()
c.Bound(Function(m) m.Line2).Hidden()
c.Bound(Function(m) m.Line3).Hidden()
c.Bound(Function(m) m.MI).Hidden()
c.Bound(Function(m) m.Suffix).Hidden()
c.Bound(Function(m) m.Gender).Hidden()
c.Bound(Function(m) m.Phone).Hidden()
c.Bound(Function(m) m.Email).Hidden()
c.Bound(Function(m) m.City).Hidden()
c.Bound(Function(m) m.State).Hidden()
c.Bound(Function(m) m.Zip).Hidden()
c.Bound(Function(m) m.FirstName).Hidden()
c.Bound(Function(m) m.LastName).Hidden()
c.Bound(Function(m) m.SourceSystemKey).Hidden()
c.Bound(Function(m) m.IndividualResultId).Hidden()
c.Bound(Function(m) m.SCEntityName).Hidden()
c.Bound(Function(m) m.SCFirstName).Hidden()
c.Bound(Function(m) m.SCLastName).Hidden()
c.Bound(Function(m) m.SCPhone).Hidden()
c.Bound(Function(m) m.HiddenDOB).Hidden()
c.Bound(Function(m) m.FundingCounty).Hidden()
c.Bound(Function(m) m.Region).Hidden()
c.Bound(Function(m) m.BSU).Hidden()
c.Bound(Function(m) m.AssignedSCUserID).Hidden()
c.Bound(Function(m) m.AssignedSCSupervisorUserID).Hidden()
End Sub).
DataSource(Sub(s) s.Ajax().ServerOperation(False)))
</div>
</div>
End If
#Html.HiddenFor(Function(m) m.Mode)
#Html.Hidden("SelectedMciNum")
#Html.Hidden("SelectedSSN")
#Html.Hidden("SelectedName")
#Html.Hidden("SelectedDOB")
#Html.Hidden("SelectedFirstName")
#Html.Hidden("SelectedLastName")
#Html.HiddenFor(Function(m) m.FilingOrganizationFilter)
<input type="hidden" id="CallingPage" name="CallingPage" value="#Model.CallingPage" />
</div>
End Using
</div>
<script type="text/javascript">
$(document).ready(function () {
$(this).keypress(function (e) {
if (e.keyCode == 13) {
$('#search').click();
e.preventDefault();
}
})
$("#Search").focus();
$("#Identifier:text").on("focus", function () {
var input = $(this);
setTimeout(function () { input.select(); });
});
var errortext = "#Model.errorText"
if(errortext != "")
{
var errorarray = errortext.split('~');
var errormsg = "";
for (var i = 0; i <errorarray.length; i++)
{
errormsg += errorarray[i] + '<br/>';
}
errortext = errormsg.substring(0, errormsg.length - 5);
}
$("#kendoValidatorField").html(errortext);
var pageComingFrom = sessionStorage.getItem("pageComingFrom");
var isPopUp = '#isPopupMode';
if (pageComingFrom == "null" || isPopUp == 'Y') {
var btnNoIndiv = $("#btnNoIndividual");
btnNoIndiv.hide();
}
var filingOrganization = sessionStorage.getItem("filingOrganization");
//clear sessionStorage
sessionStorage.removeItem("filingOrganization");
if (!filingOrganization) {
filingOrganization = $("#FilingOrganization").val();
}
if (filingOrganization) {
$("#FilingOrganizationFilter").val(filingOrganization);
}
$("div#IndividualSearchContent").on("click", "a.MCILink", function (e) {
sessionStorage.setItem("IsContinueWithOutSelectingClicked", "No")
if ($('#IndividualMCI') && $('#IndividualMCI').length > 0) {
$('#IndividualMCI').val($(this).text());
$('#IndividualMCIDiv').html($('#IndividualMCI')[0].value)
$('#IndividualName').val($(this)[0].parentNode.nextSibling.nextSibling.innerText);
$('#IndividualNameDiv').html($('#IndividualName')[0].value);
}
var dataToSend;
var gridData = $("#SearchIndivResults").data("kendoGrid");
if (gridData != null) {
var selectedItem = this.id;
var value = gridData._data.length;
for (var i = 0; i < value; i++) {
var item = gridData._data[i];
var selectedItemRecord = item.MCI +'_'+ item.IndividualResultId+'_'+item.ProgramOffice
if (selectedItemRecord == selectedItem) {
dataToSend = item;
sessionStorage.setItem("selectedItemDOB", dataToSend.HiddenDOB.split(" ")[0])
sessionStorage.setItem("selectedItemMCI", dataToSend.MCI)
sessionStorage.setItem("selectedItemName", dataToSend.Name)
sessionStorage.setItem("selectedItemProgEffDt", dataToSend.ProgramEffectiveDates)
sessionStorage.setItem("selectedItemPO", dataToSend.ProgramOffice)
sessionStorage.setItem("selectedItemSS", dataToSend.SourceSystem)
sessionStorage.setItem("selectedItemSSKey", dataToSend.SourceSystemKey)
sessionStorage.setItem("selectedItemSSN", dataToSend.SSN)
sessionStorage.setItem("selectedItemWaiver", dataToSend.Waiver)
sessionStorage.setItem("selectedItemLine1", dataToSend.Line1)
sessionStorage.setItem("selectedItemLine2", dataToSend.Line2)
sessionStorage.setItem("selectedItemLine3", dataToSend.Line3)
sessionStorage.setItem("selectedItemMI", dataToSend.MI)
sessionStorage.setItem("selectedItemSuffix", dataToSend.Suffix)
sessionStorage.setItem("selectedItemGender", dataToSend.Gender)
sessionStorage.setItem("selectedItemPhone", dataToSend.Phone)
sessionStorage.setItem("selectedItemEmail", dataToSend.Email)
sessionStorage.setItem("selectedItemCity", dataToSend.City)
sessionStorage.setItem("selectedItemCounty", dataToSend.ResidentialCounty)
sessionStorage.setItem("selectedItemFundingCounty", dataToSend.FundingCounty)
sessionStorage.setItem("selectedItemRegion", dataToSend.Region)
sessionStorage.setItem("selectedItemState", dataToSend.State)
sessionStorage.setItem("selectedItemZip", dataToSend.Zip)
sessionStorage.setItem("selectedItemIndividualResultId", dataToSend.IndividualResultId)
sessionStorage.setItem("selectedItemSCEntityName", dataToSend.SCEntityName)
sessionStorage.setItem("selectedItemSCFirstName", dataToSend.SCFirstName)
sessionStorage.setItem("selectedItemSCLastName", dataToSend.SCLastName)
sessionStorage.setItem("selectedItemSCPhone", dataToSend.SCPhone)
sessionStorage.setItem("selectedItemHiddenDOB", dataToSend.HiddenDOB)
sessionStorage.setItem("selectedBSU", dataToSend.BSU)
sessionStorage.setItem("selectedAssignedSCUserID", dataToSend.AssignedSCUserID)
sessionStorage.setItem("selectedAssignedSCSupervisorUserID", dataToSend.AssignedSCSupervisorUserID)
}
}
}
$("#SelectedMciNum").val($(this).text());
if ($("#IndividualSearchWindow").data("kendoWindow")) {
$("#IndividualSearchWindow").data("kendoWindow").close();
}
e.preventDefault();
})
$('#btnNoIndividual').click(function (e) {
sessionStorage.setItem("IsContinueWithOutSelectingClicked", "Yes")
window.location.href = baseUrl + "ComplaintIndividualInformation/Index";
})
$('#btnNoMCI').click(function (e) {
window.location.href = baseUrl + "IndividualDetail/IndividualHasNoMCI";
})
ValidateTextDate();
});
</script>
P.S. The weirdest thing to me is that in IE9 it all displays as expected. But no luck in Chrome or FF.
I will really appreciate any help on this.

Related

Html.CheckBoxFor Returning Incorrect Value If Originally Unchecked

I have a ViewModel containing information for an object called ContactEvent. ContactEvent has a boolean called IsActive. I'm using #Html.CheckBoxFor() for a checkbox to let the user alter its value. The problem is that if the value is originally true and the user sets it to false, the model passed through the POST has the updated value. But if the value is originally false, the model passed through the POST always returns false still. I have no idea what is causing it.
View
#model ContactEventViewModel
#{
ViewBag.Title = "Contact Event";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<head>
<script src="~/datatables/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="~/datatables/css/jquery.dataTables.min.css" />
</head>
<body>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
#using (Html.BeginForm("ContactEvent", "ContactEvents", FormMethod.Post))
{
<h1>Edit Contact Event</h1>
#Html.HiddenFor(Model => Model.ContactEvent.ContactEventSysID, new { #Value = Model.ContactEvent.ContactEventSysID })
<div class="form-group row">
<label>Customer</label>
<div class="col-md-7 col-lg-7">
<Label>#String.Format("{1}, {0}", Model.Customer.FirstName, Model.Customer.LastName)</Label>
#Html.HiddenFor(Model => Model.Customer.CustomerSysID, new { #Value = Model.Customer.CustomerSysID })
</div>
</div>
<div class="form-group row">
<label>Date</label>
<div class="col-md-7 col-lg-7">
#Html.EditorFor(model => model.ContactEvent.Date, new { htmlAttributes = new { #class = "datepicker", #Name = "date", #PlaceHolder = "mm/dd/yyyy" } })
</div>
</div>
<div class="form-group row">
<label>Event Type</label>
<div class="col-md-7 col-lg-7">
#Html.DropDownListFor(Model => Model.ContactEvent.ContactEventTypeSysID, new SelectList(Model.ListOfContactEventTypes, "ContactEventTypeSysID", "Description"))
</div>
</div>
<div class="form-group row">
<label>Outcome</label>
<div class="col-md-7 col-lg-7">
#Html.DropDownListFor(Model => Model.ContactEvent.OutcomeSysID, new SelectList(Model.ListOfOutcomes, "OutcomeSysID", "Description"))
</div>
</div>
<div class="form-group row">
<label>Note</label>
<div class="col-md-7 col-lg-7">
#Html.TextBoxFor(Model => Model.ContactEvent.Note, new { #Value = Model.ContactEvent.Note })
</div>
</div>
<div class="form-group row">
<label>Created Date</label>
<div class="col-md-7 col-lg-7">
<label>#Model.ContactEvent.CreatedDate</label>
</div>
</div>
<div class="form-group row">
<label>Last Updated Date</label>
<div class="col-md-7 col-lg-7">
<label>#Model.ContactEvent.LastUpdatedDate</label>
</div>
</div>
<div class="form-group row">
<label>Active?</label>
<div class="col-md-7 col-lg-7">
#Html.CheckBoxFor(Model => Model.ContactEvent.IsActive, new { #Value = Model.ContactEvent.IsActive })
</div>
</div>
<input type="submit" id="updateButton" value="Submit" />
}
</div>
</body>
Method in Controller
[HttpPost]
public IActionResult ContactEvent(ContactEventViewModel contactEventViewModel)
{
if (ModelState.IsValid)
{
string connectionString = Startup.ConnectionString;
string query = "UPDATE [CRM].[dbo].[ContactEvent] " +
"SET [Date]=#Date, [ContactEventTypeSysID]=#ContactEventTypeSysID, [OutcomeSysID]=#OutcomeSysID, [Note]=#Note, [LastUpdatedDate]=#LastUpdatedDate, [IsActive]=#IsActive " +
"WHERE [ContactEventSysID]=#ContactEventSysID";
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Parameters.AddWithValue("#Date", contactEventViewModel.ContactEvent.Date);
command.Parameters.AddWithValue("#ContactEventTypeSysID", contactEventViewModel.ContactEvent.ContactEventTypeSysID);
command.Parameters.AddWithValue("#OutcomeSysID", contactEventViewModel.ContactEvent.OutcomeSysID);
if (contactEventViewModel.ContactEvent.Note == null)
{
command.Parameters.AddWithValue("#Note", DBNull.Value);
}
else
{
command.Parameters.AddWithValue("#Note", contactEventViewModel.ContactEvent.Note);
}
command.Parameters.AddWithValue("#LastUpdatedDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
command.Parameters.AddWithValue("#IsActive", contactEventViewModel.ContactEvent.IsActive);
command.Parameters.AddWithValue("#ContactEventSysID", contactEventViewModel.ContactEvent.ContactEventSysID);
connection.Open();
command.ExecuteNonQuery();
}
}
}
return RedirectToAction("ContactEvent", "ContactEvents", new { ContactEventSysID = contactEventViewModel.ContactEvent.ContactEventSysID });
}
Let me know if you need any other code. Thanks in advance.
Please remove #Value = Model.ContactEvent.IsActive. This will let your model properly handle the value. Do not set any values unless you are sure, that you want to override model behavior.

two submit buttons for different form within the same view and controller

I have a view screen that has two different form on it, that will be activated differently. if the first button is clicked, the first form comes up and the user can fill and submit after which he proceed to click the other button to activate the other form which will then be submitted to a different table. I tried giving it different each submit button different name but my controller isn't recognizing the name. any help will be appreciated.
this is my view presently
<div class="container">
<form class="form-horizontal" role="form" method="post" id="head">
<div class="form-group">
<label for="warehouse" class="col-sm-2 control-label">Transaction type</label>
<div class="col-sm-7">
#Html.TextBoxFor(m => m.vwint0, ViewBag.action_flag == "Create" ? (object)new { #class = "form-control", style = "width : 120px", #maxlength = 10 } : new { #disabled = "disabled", style = "width : 120px" })
#Html.ValidationMessageFor(m => m.vwint0)
</div>
</div>
<div class="form-group">
<label for="code" class="col-sm-2 control-label">Customer code</label>
<div class="col-sm-7">
#Html.DropDownListFor(m => m.vwstring1, ViewBag.cus as SelectList, "Select", new { #class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<button type="submit" class="btn btn-primary" name="update" value="headsub">Submit</button>
</div>
</div>
</form>
<form class="form-horizontal" role="form" method="post" id="details">
<div class="form-group">
<label for="firstName" class="col-sm-2 control-label">Sale sequence number </label>
<div class="col-sm-9">
#Html.TextBoxFor(m => m.vwint0, new { #class = "form-control", style = "width : 80px", maxlength = 10 })
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Quote sequence</label>
<div class="col-sm-9">
#Html.TextBoxFor(m => m.vwstring9, new { #class = "form-control", style = "width : 80px", maxlength = 10 })
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Item code</label>
<div class="col-sm-9">
#Html.DropDownListFor(m => m.vwstring10, ViewBag.item as SelectList, "Select", new { #class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<button type="submit" class="btn btn-primary" name="update" value="detailsub">Submit</button>
</div>
</div>
</form>
</div>
In my controller, I tried this but my controller isn't even recognizing the button name.
if (update == "headsub")
{
AR_002_SALES gdoc = new AR_002_SALES();
gdoc.sale_sequence_number = glay.vwint0;
gdoc.customer_code = glay.vwstring1;
gdoc.currency_code = glay.vwstring2;
}
else
{
AR_002_QUOTE = new AR_002_QUOTE();
AR_002_QUOTE.sale_sequence_number = glay.vwint0;
AR_002_QUOTE.quote_sequence = glay.vwstring9;
AR_002_QUOTE.item_code = string.IsNullOrWhiteSpace(glay.vwstring10) ? "" : glay.vwstring10;
AR_002_QUOTE.quote_qty = glay.vwdclarray0[0];
AR_002_QUOTE.price = glay.vwdclarray0[1];
}
Instead of using <form class="form-horizontal" role="form" method="post" id="head">
use #using (Html.BeginForm("ActionMethod", "Controller", FormMethod.Post, new { #class = "form-horizontal" ,#id="head" }))
to submit a form and action method will process that form and does stuff.Similarly you can do for another form also.
In your .cshtml it looks like it will not hit any action method of that controller.

is their anyway to return nothing in actionResult not to refresh that page if validations raised

this is my actionResult
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Payment(PaymentViewModel payment, string returnUrl)
{
PaymentModel paymentModel = new PaymentModel();
if (ModelState.IsValid)
{
CreditCardDetailsModel creditCardDetailsModel = new CreditCardDetailsModel();
creditCardDetailsModel.SecurityId = payment.SecurityId;
creditCardDetailsModel.ExpiryDate = payment.Month + payment.Year;
creditCardDetailsModel.CardNumber = payment.CardNumber;
paymentModel.CreditCardDetails = creditCardDetailsModel;
TempData["model"] = paymentModel;
return RedirectToAction("Payment");
}
var query = from state in ModelState.Values
from error in state.Errors
select error.ErrorMessage;
var errorList = query.ToList();
TempData["ErrorMessages"] = errorList;
ViewBag.MonthList = new SelectList(new[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" });
return new EmptyResult();
}
This is my partialView
#model Centra.Web.ViewModels.PaymentViewModel #using (Html.BeginForm("Payment", "Flight", FormMethod.Post,null))
{
#Html.AntiForgeryToken()
<div class="row space-form traveller-form">
<div class="col-lg-12">
<div class="col-lg-3 row">
<div class="fomr-group text-right">
<label>Credit Card No</label>
</div>
</div>
<div class="col-lg-8">
<div class="fomr-group col-lg-5 cardDetails">
#Html.TextBoxFor(p => p.CardNumber, new { #class = "form-control" })
</div>
<div ng-if="creditCardError == true" class="fomr-group col-lg-2 cardDetails">
<label>Please enter valid card number</label>
</div>
</div>
</div>
<div class="col-lg-12">
<div class="col-lg-3 row">
<div class="fomr-group text-right">
<label>Expiry Date</label>
</div>
</div>
<div class="col-lg-8">
<div class="fomr-group col-lg-2 cardDetails ">
#Html.DropDownListFor(m=>m.Month, (SelectList)ViewBag.MonthList)
</div>
<div class="fomr-group col-lg-3 cardDetails row">
#Html.DropDownListFor(p => p.Year, Enumerable.Range(DateTime.Now.Year, 20)
.Select(x => new SelectListItem
{
Text = x.ToString(),
Value = x.ToString()
}
), new { #class = "form-control" })
</div>
</div>
</div>
<div class="col-lg-12">
<div class="col-lg-3 row">
<div class="fomr-group text-right">
<label>Name on card</label>
</div>
</div>
<div class="col-lg-8">
<div class="fomr-group col-lg-5 cardDetails">
#Html.TextBoxFor(p => p.NameOnCard, new { #class = "form-control" })
</div>
</div>
</div>
<div class="col-lg-12">
<div class="col-lg-3 row">
<div class="fomr-group text-right">
<label>CVV</label>
</div>
</div>
<div class="col-lg-8">
<div class="fomr-group col-lg-2 cardDetails">
#Html.TextBoxFor(p => p.SecurityId, new { #maxlength = "4", #class = "form-control", #placeholder = "CVV" })
</div>
<div class="fomr-group col-lg-5 cardDetails TotalPrice">
<label>The 3 digit number printed on the back of card</label>
</div>
</div>
</div>
<div class="col-lg-12 terms-conditions">
<div class="col-sm-11 col-lg-offset-1">
<div class="checkbox">
<label>
#* #Html.CheckBox("paymentCheckbox", new { #onclick = "function-to-open-dialog()" })*#
<input type="checkbox" id="paymentCheckbox" ng-model="paymentCheckbox">
I understand and agree to the rules and notifications of this fare, the booking privacy policy and the terms & conditions Centra Travels.
</label>
</div>
</div>
</div>
<div class="col-lg-12">
<div class="col-lg-2 row">
<div class="fomr-group text-right">
</div>
</div>
<div class="col-lg-9 row">
<div class="fomr-group TotalPrice">
<label>
<h3>$ 36,613</h3>
<span>(Total inclusive all taxes)</span>
</label>
</div>
</div>
</div>
<div class="col-lg-12">
<div class="col-lg-2 row">
<div class="fomr-group text-right">
</div>
</div>
<div class="col-lg-2 row">
<div class="fomr-group text-right col-lg-2">
#*<button type="submit" ng-disabled="!paymentCheckbox" ng-click="Payment(PaymentDetails)" class="btn btn-info makePaymentbtn">Make a Payment</button>*#
<button type="submit" ng-disabled="!paymentCheckbox" class="btn btn-info makePaymentbtn">Make a Payment</button>
</div>
#Html.Hidden("returnUrl", this.Request.RawUrl)
</div>
</div>
</div>
}
And other partialPages are not in mvcRazor formate their are in angular, so when i redirect to specific view(FlighBooking) //FlightBooking is my mainView in that multiple partial views are their, it is rending the FlightBooking View with but angular partialview are losing its states, so i tried by returning as return new EmptyResult(); but the page state is loosing, what should i do?
I want to bee on that same page without loosing its state if validations fails
If you don't want to refresh your page after go to action, you should use #Ajax.BeginForm instead #Html.BeginForm. There are a lot of tutorials on the internet.

Submit Button on Razor View doesn't call Action Result - MVC

I have an issue with my submit button not calling the actionresult. I have set the breakpoint in the action result itself so i know that the actionResult is not even being called. Thank you in advance for your guidance.
View:
#model CCQAS.WebApp.Areas.Credentialing.Models.TransferCustodyViewModel
#using CCQAS.API.Model.Enums
#{var PersonId = ViewBag.SessionPersonId;}
#{ViewBag.Title = "Transfer Custody ";
ViewBag.HelpText = "When this record transfer becomes effective, responsibility for updating and maintaining this credentials record will be transferred to the gaining UIC";}
#using (Html.BeginForm("CreateCustodyTransfer", "TransferCustody", FormMethod.Post, new { #id = "transfer-custody-form", #role = "form" }))
{
#Html.AntiForgeryToken()
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
Transfer Custody for #Html.DisplayFor(model => model.LastNameCommaFirstName)
#Html.Partial("_SectionHelp", (string)ViewBag.HelpText)
</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-4 col-md-4">
<div class="form-group require">
#Html.LabelFor(model => model.UIC, "Transfer Record To")
<div class="input-group focus" tabindex="0" id="uic_txt">
#Html.EditorFor(model => model.UIC, "Uic", new { serviceLevel = true })
</div>
#Html.ValidationMessageFor(model => model.UIC)
</div>
</div>
<div class="col-sm-4 col-md-4">
<div class="form-group require">
#Html.LabelFor(model => model.ReasonId)
#Html.EnumDropDownListFor(model => model.ReasonId, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.ReasonId)
</div>
</div>
<div class="col-sm-4 col-md-4">
<div class="form-group require" hidden="hidden" id="divOtherReason">
#Html.LabelFor(model => model.OtherReasonTxt)
#Html.TextBoxFor(model => model.OtherReasonTxt, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.OtherReasonTxt)
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4 col-md-4">
<div class="form-group require">
#Html.LabelFor(model => model.EffectiveDateString)
#Html.TextBoxFor(model => model.EffectiveDateString, new { #class = "form-control", #disabled = "disabled" })
#Html.ValidationMessageFor(model => model.EffectiveDate)
</div>
</div>
</div>
</div>
<div class="panel-footer text-center">
<input type="submit" value="Submit" data-loading-text="Submitting..." class="btn btn-primary" autocomplete="off" id="submitButton" />
<button type="button" onclick="goBack()" class="btn btn-default">Cancel</button>
</div>
</div>
</div>
</div>
}
#section scripts{
<script>
$(function () {
var uic = $("#UIC");
var reasonId = $("#ReasonId");
var otherReason = $("#OtherReasonTxt");
$('#submitButton').click(function (event) {
if ((uic.val() != "" && reasonId.val() != "" && reasonId.val() != 99999) || (uic.val() != "" && reasonId.val() != "" && otherReason.val() != "")) {
if (!confirm("Are you sure you want to transfer custody?")) {
resetButtonState();
return false;
}
}
});
});
function goBack() {
window.location.href = document.referrer;
}
$('#ReasonId').change(function () {
toggleOtherReason();
});
//Other Reason fields will only display if "Other" is selected from the ReasonId drop down list
function toggleOtherReason() {
var reasonId = $("#ReasonId").val();
if (reasonId == 99999) {
$("#divOtherReason").show();
}
else {
$("#divOtherReason").hide();
}
}
</script>
}
Controller:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CreateCustodyTransfer(TransferCustodyViewModel viewModel)
{
string serviceCode = null;
var result = mtfService.GetMtfId(viewModel.UIC, serviceCode, null);
viewModel.MTFId = (long)result;
var model = new CredCustody();
{
model.UIC = viewModel.UIC;
model.ReasonId = viewModel.ReasonId;
model.OtherReasonTxt = viewModel.OtherReasonTxt;
model.UserMtfId = CurrentUser.PrimaryMtfId;
model.UserText = CurrentUser.Name;
model.CredProviderId = this.CredProvider.CredProviderId;
model.AuditUserId = CurrentUser.UserId;
model.MTFId = viewModel.MTFId;
};
long credCustodyId = this.credCustodyService.CreateCredCustody(model);
SetPageMessage(PageMessageType.Success, String.Format("Custody Transferred"));
return RedirectToAction("SearchResults", "ProviderSearch");
}

dropdownlist in partial view not expanding

I am developing an asp.net MVC4 web app where I need to show StateList and CountryList. I am having a dropdownlist for Countries and on changing i am getting a partial view to display the corresponding States through an ajax request. The partial view has the dropdownlist for States. But once rendered, the dropdownlist for States is not expanding. Here is the code.
First View:
<div class="row" style="margin-left: 12%">
<div class="col-md-12 control-group">
<label class="col-md-4 control-label" style="margin-top :1%;"><b>Country:</b></label>
<div class="col-md-4" style="">
#Html.DropDownListFor(Function(model) model.SelectedCountryId, Model.CountryList, New With {.style = "width:100px", .type = "text", .id = "country"})
#Html.ValidationMessageFor(Function(model) model.SelectedCountryId)
</div>
</div>
</div>
<div id="stateDiv"></div>
Script:
$(document).ready(function () {
var rootUrl = $('#rootUrl').val();
$('#country').change(function () {
var countryCode = $(this).val();
$.get(rootUrl + 'GetStateList', { countryCodeId: countryCode }, function (data) {
$('#stateDiv').html(data);
}, 'html');
var isUSCAN = false;
if ($(this).val() == 1 || $(this).val() == 2) {
isUSCAN = true;
}
$('#stateSelect').toggle(isUSCAN);
$('#stateText').toggle(!isUSCAN);
var isCAN = $(this).val() == 2;
$('#provinceLabel').toggle(isCAN);
$('#stateLabel').toggle(!isCAN);
}).change();
});
Controller:
Function GetStateList(countryCodeId As Integer) As ActionResult
Return PartialView("PartialStateList", Defendant)
End Function
PartialStateList View
<div class="row" style="margin-left: 12%">
<div class="col-md-12 control-group">
<label id="stateLabel" class="col-md-4 control-label" style="margin-top :1%;"><b>State:</b></label>
<label id="provinceLabel" class="col-md-4 control-label" style="margin-top :1%;"><b>Province:</b></label>
<div class="col-md-4" style="">
#Html.DropDownListFor(Function(model) model.SelectedStateId, Model.StateList, New With {.style = "width:100px", .type = "text", .id = "stateSelect"})
#Html.TextBoxFor(Function(model) model.SelectedStateId, New With {.style = "width:100px", .value = "", .type = "text", .id = "stateText"})
#Html.ValidationMessageFor(Function(model) model.SelectedStateId)
</div>
</div>
</div>
The html that is rendered when i check in browser has the entire list of states, but when i click on the dropdownlist, it is not expanding and showing the list. Please let me know if there is something I am missing.

Resources