score:1
Accepted answer
Fix it myself by using below:
LayoutAdmin view:
<script>
$(function () {
$.ajaxSetup({ cache: false });
$("#impersonate").on("click", function (e) {
// hide dropdown if any
$(e.target).closest('.btn-group').children('.dropdown-toggle').dropdown('toggle');
$('#myModalContent').load(this.href, function () {
$('#myModal').modal({
/*backdrop: 'static',*/
keyboard: true
}, 'show');
bindForm(this);
});
return false;
});
});
function bindForm(dialog) {
$('form', dialog).submit(function () {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (result) {
if (result.success) {
$('#myModal').modal('hide');
//Refresh
location.reload();
} else {
$('#myModalContent').html(result);
bindForm();
}
}
});
return false;
});
}
</script>
Impersonation.cshtml:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Impersonation(FAB_View model)
{
if (ModelState.IsValid)
{
UserRoleHelper userrolehelper = new UserRoleHelper();
var loggedonuser = userrolehelper.GetLoggedOnUser();
var currentuser = userrolehelper.GetCurrentUser();
bool validuser = userrolehelper.CheckValidUser(model.UserName);
if (validuser == false)
{
ViewBag.Error = "* Don't have such user!";
return PartialView("Impersonation", model);
//return Json(new { success = false });
}
else
{
//userrolehelper.StartImpersonate(model.UserName);
return Json(new { success = true });
}
}
return PartialView("Impersonation", model);
}
score:0
Try this Modify (Partial View) Impersonation.csthml:
@model FAB_Portal.Models.FAB_View
@using (Html.BeginForm("Impersonation", "UserRoles", FormMethod.Post,new { @id="form" }))
{
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> Impersonation</h4>
</div>
<div class="modal-body">
<div class="form-horizontal">
@Html.Label("Impersonate", htmlAttributes: new { @class = "control-label col-md-4" })
@Html.TextBox("UserName", null, htmlAttributes: new { @class = "form-control" })
<text class="text-danger">@ViewBag.Error</text>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a class="btn btn-danger btn-ok" id="impersonate" data-dismiss="modal">Submit</a>
</div>
</div>
</div>
}
<script type="text/javascript">
$("a#impersonate").click(function () {
$.ajax({
type: "POST",
url: "@Url.Action("Impersonation", "UserRoles")",
data: $('#form').serialize(),
success: function (result) {
if (result == "success") {
$('#dialogDiv').modal('hide');
} else {
$('#dialogContent').html(result);
}
}
});
});
</script>
UserRoles.Controller:
[HttpPost]
public ActionResult Impersonation(FAB_View model)
{
if (ModelState.IsValid)
{
UserRoleHelper userrolehelper = new UserRoleHelper();
bool validuser = userrolehelper.CheckValidUser(model.UserName);
if (validuser == false)
{
ViewBag.Error = "Don't have such user!";
return Content("error");
}
userrolehelper.StartImpersonate(model.UserName);
}
return Content("success");
}
Try this and don't forget to Hit like if it works. Let me know if it's not working going to provide another way or modify this one.
Related Query
- Bootstrap modal dialog return message in MVC
- ASP.NET MVC 4 Open Bootstrap modal with jquery
- MVC Passing data to and from Bootstrap Modal
- Return Json causes save file dialog in asp.net mvc
- time-picker in bootstrap modal dialog
- javascript/jquery modal popup dialog MVC 4 / render partial view
- How to get a bootstrap modal dialog box to fade away slowly
- Cannot display bootstrap dialog with an asp.net mvc url.action link
- Bootstrap modal dialog not showing when using fade animation
- Bootstrap modal dialog button click event triggering on modal open
- How to create bootstrap 4 confirmation modal for delete in ASP.NET MVC
- MVC 5 JQuery Bootstrap Modal using PartialView
- Is there a way to put the document in "focus" after a Twitter Bootstrap modal dialog is closed?
- Jquery close bootstrap modal dialog completedly
- Rails form input fields overflowing with Bootstrap 3 modal dialog
- Validation in bootstrap modal dialog
- required field - validation doesn't display in bootstrap modal popup MVC
- modal dialog not dismissing bootstrap
- How to delete tr row from table with modal dialog using bootstrap
- Return Validation Error back to jQuery dialog in MVC 3
- How to use Bootstrap popovers in mvc validation message
- MVC return view to dialog
- How to get value from bootstrap modal using jQuery in ASP.NET MVC
- asp.net mvc 4 registration inside bootstrap modal plugin
- Is it possible to display a jQuery modal dialog box with .toggle() method?
- Jquery Modal Dialog disables form elements
- Passing Data in and out of CKEditor / jQuery-UI Modal Dialog
- Bootstrap Datetimepicker modal calendar position append not working
- Passing data into a bootstrap modal
- Bootstrap modal on form submit not displaying at correct point
- Is not deleting from bootstrap modal
- Give user feedback in asp.net mvc just before json return
- Select Not Populating in Dynamically ID'd Bootstrap 4 Modal
- How to update Bootstrap modal calendar events
- How to Refresh the Bootstrap modal fields after modal close
- Bootstrap modal automatically closing on scroll
- Bootstrap Modal not working in IE, tried all other solutions on Stack
- Adding Warning icon to Bootstrap Dialog
- How to hide alert message in MVC
- Bootstrap modal only works after refreshing page
- Hiding bootstrap modal from jQuery doesn't work the first time
- Bootstrap Modal with mysql data
- Exposing element outside modal-backdrop in CSS Bootstrap jquery modal
- Jquery Dialog modal issues
- Twitter Bootstrap modal should create new instance every time it opens
- Display a modal Pop up in ASP.NET MVC
- twitter bootstrap modal with popover inside
- Opening bootstrap modal with double click
- Modal Dialog Jquery UI Blackberry Curve Issue
- Bootstrap Modal buttons do not respond to click
More Query from same tag
- AJAX requests not executing in parallel using $.when(...)
- How to identify when select option was selected (not necessarily changed)?
- Knockout JS Mapping from JSON not working
- Passing execution from one click event in js file to another function in another js file
- Concat Objects in AngularJS
- what it means on( 'click.something', function() {..}); in jquery?
- How to force close ipad/iphone keypad when input element is not focused using JS?
- Track sign-ups with facebook pixel on click (JS/JQUERY code)
- Passing An Array of Values To Jquery
- Add listener to dynamically added HTML within closure?
- Select element by data attribute after it's change
- Disable tab cloning after 3rd clone
- Upload image using ajax and form submitting
- Continuous Html5 audio .play() with only 1st time trigger
- Remove everything after a certain character in txt file
- Javascript Equivalent of Jquery
- Why doesn't css 100% - 100% work without absolute?
- Kendo UI for jQuery Grid date not posting to the server side
- jQuery UI Vertical Tabs makes page scroll "stick"
- jQuery - Addition within .each() sum loop causing issue
- Typeahead.js not showing dropdown
- How to select and check these types of checkboxes based on values?
- Use dynamic input fields in combination with php foreach
- Div showing on clicking button twice in the initial state
- I am trying to put tabs within an accordion
- How do i update one Jquery Chosen Dropdown on another chosen dropdown Selection Change
- How to append html only if the div is empty in jQuery?
- jQuery validate in tabs only works on first submit
- How to close collapsible by clicking button
- Dropdown with categories and subcategories