dropdownlist in partial view not expanding - asp.net-mvc

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.

Related

MVC ViewModel bound list is empty

I am using ASP.NET MVC in VB. This is the "CreateStuffViewModel", which is a view model for my "Stuff" class:
Public Property Name() As String
Public Property Description() As String
Public Property ItemNames() As List(Of String)
In the View for creating a Stuff, the model being used is the above view model. I have a dropdown combobox containing the names of all of the user's Items, which is created in the controller in the Get. The user can select an item in the combobox, then hit an "Add" button, which adds that text to a list box. When the user hits the "Create" button, the text items in the list box are supposed to be in the ItemNames list.
This is the Get function:
' GET: Stuff/Create
Function Create() As ActionResult
Dim selectItem As New List(Of SelectListItem)
Dim curUserID = User.Identity.GetUserId()
Dim listOfItems = db.Items.Where(Function(x) x.MyUser.Id = curUserID)
For Each item In listOfItems
selectItem.Add(New SelectListItem() With {.Value = item.ID, .Text = item.Name})
Next
ViewData("selectItem") = selectItem
Dim newStuff As CreateStuffViewModel = New CreateStuffViewModel
newStuff.ItemNames = New List(Of String)
Return View(newStuff)
End Function
Then this is the view:
#ModelType CreateStuffViewModel
#Code
ViewData("Title") = "Create"
'This is the list of items that was created in the controller
Dim selectItem As New List(Of SelectListItem)
selectItem = ViewData("selectItem")
Dim selItems As New List(Of SelectListItem)
End Code
<h2>Create</h2>
#Using (Html.BeginForm())
#Html.AntiForgeryToken()
#<div class="form-horizontal">
<br />
<br />
<h4>Create a new Stuff</h4>
<hr />
#Html.ValidationSummary(True, "", New With { .class = "text-danger" })
<div class="form-group">
#Html.LabelFor(Function(model) model.Name, htmlAttributes:= New With { .class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(Function(model) model.Name, New With { .htmlAttributes = New With { .class = "form-control" } })
#Html.ValidationMessageFor(Function(model) model.Name, "", New With { .class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(Function(model) model.Description, htmlAttributes:= New With { .class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(Function(model) model.Description, New With { .htmlAttributes = New With { .class = "form-control" } })
#Html.ValidationMessageFor(Function(model) model.Description, "", New With { .class = "text-danger" })
</div>
</div>
#*This is the dropdown list containing the strings of item names*#
<div class="form-group">
<div class="control-label col-md-2" style="font-weight: bold">Select an existing Item</div>
<div class="col-md-10" id="ItemsList">
#Html.DropDownList("AvailItems", selectItem)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="button" value="Add Item" class="btn btn-default" id="AddItem"/>
</div>
</div>
#*This is the list box to which the Add button adds the item text*#
<div class="form-group">
<div class="control-label col-md-2" style="font-weight: bold">Items in Stuff</div>
<div class="col-md-10">
#Html.ListBoxFor(Function(model) model.ItemNames, New SelectList(selItems), htmlAttributes:=New With {.name = "ItemNames"})
<div class="btn-group-vertical">
<div class="btn-link">Move Up</div>
<div class="btn-link">Move Down</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="button" value="Remove Selected Item" class="btn btn-default" id="RemoveItem"/>
</div>
</div>
<br />
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
End Using
<div>
#Html.ActionLink("Back to List", "Index")
</div>
#Section Scripts
#Scripts.Render("~/bundles/jqueryval")
#*Script for adding selected item from drop down to the list*#
<script>
$('#AddItem').click(function () {
var selection = $('#ItemsList :selected').text();
selection.trim();
var x = document.getElementsByName("ItemNames");
var i;
for (i = 0; i < x.length; i++) {
if (x[i].type == "select-multiple") { //listbox
x[i].options.add(new Option(selection, selection));
}
}
});
</script>
#*Script for removing selected item from list*#
<script>
$('#RemoveItem').click(function () {
var x = document.getElementsByName("ItemNames");
var listBox;
var i;
for (i = 0; i < x.length; i++) {
if (x[i].type == "select-multiple") { //listbox
listBox = x[i];
}
}
if (listBox.selectedIndex >= 0) {
var sel = listBox.options[listBox.selectedIndex];
listBox.options.remove(sel);
}
});
</script>
End Section
And this is the Post function:
' POST: Stuff/Create
'To protect from overposting attacks, please enable the specific properties you want to bind to, for
'more details see http://go.microsoft.com/fwlink/?LinkId=317598.
<HttpPost()>
<ValidateAntiForgeryToken()>
Async Function Create(ByVal model As CreateStuffViewModel) As Task(Of ActionResult)
If ModelState.IsValid Then
Dim newStuff = New Stuff() With {
.Name = model.Name,
.Description = model.Description
}
Dim curUserID = User.Identity.GetUserId()
Dim thisUser As AppUser = db.Users.Where(Function(x) x.Id = curUserID).FirstOrDefault()
newStuff.MyUser = thisUser
'model.ItemNames is Nothing:
Dim thisList As List(Of String) = model.ItemNames
If thisList IsNot Nothing Then
Dim thisItem As Item
For Each item In thisList
thisItem = (From thing In db.Items Select thing Where thing.MyUser.Id = curUserID AndAlso thing.Name = item)
newStuff.Items.Add(thisItem)
Next
End If
db.Stuffs.Add(newStuff)
Await db.SaveChangesAsync()
Return RedirectToAction("Index")
End If
Return View(model)
End Function
So the view works fine - the Add button adds the text to the list box as expected. But when I hit the "Create" button, in the controller, the ItemNames list is NOTHING, and I do not know why.
Any help is greatly appreciated!

How to toggle Partial View on Single Submit Button in MVC?

Here is my Code
View
#using (Html.BeginForm("userrights", "Users", FormMethod.Post, new { #class = "form-horizontal", role = "form"}))
{
<div class="form-group">
<div class="col-md-7" style="padding-right:10px">
#Html.TextBoxFor(m => m.companyname, new { #class = "form-control", #placeholder = "Serach By Sponser Name" })
</div>
<div class="clearfix"></div>
</div>
<div class="form-group">
<div class="col-sm-2">
<button type="submit" id="btn_search" value="Search" name="btn_search" class="btn btn-default">Search</button>
</div>
<div class="clearfix"></div>
</div>
</div>
#Html.Partial("_userRightPartial", Model._UserRightPartialView)
<div class="clear"></div>
}
Controller Method
public ActionResult userrights()
{
IEnumerable<MenuListModel> _MenuListModel = _ftwCommonMethods.GetMenuItems();
IEnumerable<SubMenuListModel> _SubMenuListModel = _ftwCommonMethods.GetSubMenuItems("1");
UserRightViewSearch _UserRightViewSearch = new UserRightViewSearch();
UserRightPartialView _UserRightPartialView = new UserRightPartialView();
_UserRightPartialView._SubMenuListModel = _SubMenuListModel;
_UserRightViewSearch._UserRightPartialView = _UserRightPartialView;
_UserRightViewSearch._menu = _MenuListModel;
_UserRightViewSearch.selectedMenu = 0;
return View(_UserRightViewSearch);
}
I want when page first time loads, _userRightPartial partial view should be hidden. After Submitting By Search Button it should appear.
I know it can be possible by Hide and Show DIV. But i want is there other way to do it with MVC Code?

ASP.NET MVC renders only the custom control

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.

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");
}

PagedListPager page always null

This used to work... but now the >> anchor tag of the PagedListPager always passes null to the controller for the page value required...
VS 2013 Web Express & MVC 4 with latest package updates for all.
Just like in Scot Allen's MVC 4 intro, I have a partial view with a PagedListPager
The Controller:
public ActionResult Catalog(string Id= "0", int page=1)
{
var CurrentItemsPage = (get-data-blaw-blaw-blaw).ToPagedList(page,18);
var model = new ShowRoomCatalogPackage(){ CurrentItems = CurrentItemsPage};
return View(model);
}
The catalog page
#model craftstore.Models.ShowRoomCatalogPackage
#{
ViewBag.Title = "Catalog";
Layout = "~/Views/Shared/_Details.cshtml";
}
#using (Ajax.BeginForm("Catalog", "Home", new { category = #Model.SelectedCategoryId, page = 1 },
new AjaxOptions
{
UpdateTargetId = "products",
InsertionMode = InsertionMode.Replace,
HttpMethod = "post"
}
)
)
{
<div class="container" >
<div class="row">
<div class="col-lg-10 col-md-5 col-sm-4 dropdown-menu">
#Html.LabelFor(m => m.SelectedCategoryId)
#Html.DropDownList("id", Model.CategoryItems, new { #id = "ddlCategories", onchange = "this.form.submit();" })
</div>
<div class="col-lg-2 col-md-2 col-sm-1">
#Html.ActionLink("Your Cart", "Index", "ShoppingCart", "", new { #class = "btn btn-green btn-lg" })
</div>
</div>
<div class="row">
#Html.Partial("_CatalogPartial", Model.CurrentItems)
</div><!-- row -->
</div><!-- container -->
}
<br />
<br />
#section Scripts
{
<script type="text/javascript">
new AnimOnScroll(document.getElementById('grid'), {
minDuration: 0.4,
maxDuration: 0.7,
viewportFactor: 0.2
});
</script>
}
The partial view:
#model IPagedList<ShowroomCatalog>
<div id="productList">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="pagedList" data-cs-target="#productList">
#Html.PagedListPager(Model, page => Url.Action("Index", new { category = ViewBag.SelectedCategoryId, page }), PagedListRenderOptions.MinimalWithItemCountText)
</div>
<ul class="grid effect-2" id="grid">
#foreach(var item in Model)
{
var path = String.Format("~/Content/Images/catalog/{0}/{1}", item.OfferType, item.ImagePath);
<li>
<div class="itembox">
<div class="imagebox">
<a href="#Url.Action("Detail", "Home", new { id = item.Id })" title="Detail for #item.CatalogName">
<img class="catalogimg" src="#Url.Content(path)" />
</a>
</div>
<p>#item.CatalogName</p>
</div>
</li>
}
</ul>
</div>
</div><!-- productlist -->
Now the rendered partialview in the browser doesn't have anything in the anchors which may or may not be normal...
<div class="pagedList" data-cs-target="#productList">
<div class="pagination-container"><ul class="pagination"><li class="disabled PagedList-skipToPrevious"><a rel="prev">«</a></li><li class="disabled PagedList-pageCountAndLocation"><a>Showing items 1 through 18 of 65.</a></li><li class="PagedList-skipToNext">»</li></ul></div>
</div>
And when you hover on the >> it doesn't show the page parameter in the URL:
Again, back in the Controller - I get the category (15) but no page parameter or Request.URL parameter is passed to the controller - it's not hiding because of some routing mistake...I think...
How do I get the paging control to work again...???
[EDIT: one more note - the url path on the pager is /controller/action/category/page rather than what shows up on Scot Allen's OdeToFood example where it's equivalent would be /controller/action/category?page=n (like /Home/Catalog/15?page=1 ]
I was missing the JS for the PagedList class anchor element.
var getPage = function () {
var $a = $(this);
var options = {
url: $a.attr("href"),
data: $("form").serialize(),
type: "get"
};
$.ajax(options).done(function (data) {
var target = $a.parents("div.pagedList").attr("data-otf-target");
$(target).replaceWith(data);
});
return false;
};
And this is fired off by :
$(".main-content").on("click", ".pagedList a", getPage);
BUT, this means you need to have your #RenderBody() call in your _Layout.cshtml file wrapped in something with a class of main-content. An example:
<section class="content-wrapper main-content clear-fix">
#RenderBody()
</section>

Resources