logo
down
shadow

ASP.NET MVC RemoteAttribute does not trigger action method in controller


ASP.NET MVC RemoteAttribute does not trigger action method in controller

By : Lucky Owl
Date : November 18 2020, 01:01 AM
To fix the issue you can do Because your content are loaded after the validation call. You need to call the validation and parse from after loading the partial view.
code :
$.get(url, function (data) {
    $("#containerId").html(data);
    $("#modalId").modal('show');
    var form = $('form');
    form.removeData('validator');
    form.removeData('unobtrusiveValidation');
    $.validator.unobtrusive.parse(form);
});


Share : facebook icon twitter icon
RemoteAttribute in viewmodel and ActionNameAttribute in corresponding action method (MVC3)

RemoteAttribute in viewmodel and ActionNameAttribute in corresponding action method (MVC3)


By : user3688561
Date : March 29 2020, 07:55 AM
I wish this help you What is the action name which you are supplying in the Remote attribute?
If you are supplying the name of your action method (as opposed to the name declared in the ActionName attribute), then the VirtualPathProvider will generate a URL using the underlying action method's name. If you supply the name declared in the ActionName attribute, then the URL will be generated using the method name declared in the ActionName attribute.
How to run/trigger javascript in controller action method?

How to run/trigger javascript in controller action method?


By : Kevin Windisch
Date : March 29 2020, 07:55 AM
I wish this help you I am using .Net 4.0 and a lot of solution currently on the Internet are not working, for example non-exist library.
code :
<form id="form1" method="POST" action="/controller/action">

</form>
$(function(){
    var form = $('#form1'),
        url = form.attr('action'),
        formData = form.serialize();

    form.submit(function(){
        $.post(action, formData, function(result){
            if(result)
                TriggerIframeAction();
        })
        return false;
    }
});

function TriggerIframeAction() {
    var iframe = document.getElementById("myIframe");
    var iframeForm = iframe.contentWindow.document.getElementById("myIframeForm");
    iframeForm.submit();
}
public ActionResult Action(FormCollection collection)
{
    // do something
    return Json(true);
}
ASP.NET MVC RemoteAttribute validation not working - Action not being executed

ASP.NET MVC RemoteAttribute validation not working - Action not being executed


By : Marjan Pregelj
Date : March 29 2020, 07:55 AM
I hope this helps you . Ok I found my answer.
To quote Darin Dimitrov here:
code :
$.validator.unobtrusive.parse('#registerForm');  
registerDialog.empty().html(result.viewResult);
RemoteAttribute is not passing parameter to action?

RemoteAttribute is not passing parameter to action?


By : hulu
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I am trying to use the RemoteAttribute to validate a data element serverside using JSON. My data field is: , Seems like the generated name of your input field is:
code :
name="CheckInformation.MyNumber"
@Html.TextBoxFor(x => x.CheckInformation.MyNumber)
public ActionResult IsValidMyNumber([Bind(Prefix = "CheckInformation")] string myNumber)
{
    var test = services.ValidateMyNumber(myNumber);
    return Json(test, JsonRequestBehavior.AllowGet);
}
use RemoteAttribute in modelview for Edit and Create Action

use RemoteAttribute in modelview for Edit and Create Action


By : user2861660
Date : March 29 2020, 07:55 AM
To fix the issue you can do Option 1 - Use Additional fields:
You can use the AdditionalFields argument to your remote validation attribute in your model and combine that with a hidden field in your view .
code :
[Remote("ValidUsername", "Home", ErrorMessage = "this usernaem is duplicate", AdditionalFields = "PageType")]
public string Username { get; set; }
<label asp-for="Username">Username</label>
<input asp-for="Username" />
<span asp-validation-for="Username"></span>
<input type="hidden" name="PageType" value="Edit" />
[AcceptVerbs("Get", "Post")]
public IActionResult ValidUsername(string Username, string PageType)
{
    if ("Edit".Equals(PageType))
    {
        return Json(true);
    }
    if (Username.Equals("21"))
    {


        return Json(false);
    }

    return Json(true);
}
Related Posts Related Posts :
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • Marshal.Copy attempted to read or write protected memory At Random Times
  • Restrict Type variable to specific class or subclass
  • Horizontal text alignment in a PdfPCell
  • C# crashing with Form.show() command, ObjectDisposedException - Deeper look / explanation please
  • Will the result of a LINQ query always be guaranteed to be in the correct order?
  • "Could not find default endpoint element that references contract"
  • Umbraco Request.QueryString is null if it's the first time the page is loaded
  • Error inconsistent accessibility method C#
  • How to program Intel Xeon Phi with C#?
  • remove nested element using regular expression
  • Is there a C# alternative to Java's vararg parameters?
  • Clear particular column values in DataTable
  • how to add event handler to programatically created checkboxes
  • Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'
  • Check for key in pre-existing dictionary in case insensitive manner
  • How to remove year from datetime object?
  • Accessing Settings in different ways
  • "This project is empty" error in Sonarqube
  • How to create reusable icon menu in Xamarin
  • Value Cannot be null in Ado.Net connectivity
  • Adding a custom/dynamic attribute when using XSD.exe
  • How to convert object to correct type
  • Automatically sign out from Forms Authentication in ASP.NET when browser is closed
  • Can a WCF service support both Buffered and Streamed transfer modes?
  • Verify a CA Certificate with a public key in C#
  • How to invoke a Web Service that requires the "patch" verb using the C# WebClient wrapper?
  • Proper way a implementing property based on generic type
  • Closing a form that is created in another thread
  • How Can You Bind a List<String> to a StackPanel
  • WPF Application Update Best Practices - Architectural Explanation
  • System.UnauthorizedAccessException in Server.MapPath()
  • Connecting and Using SQL Compact Edition in a WPF application
  • C#: weird ref in constructor to behave like "virtual field"
  • C# XDocument Load with multiple roots
  • How to decide what goes in the Domain or Application Project in a "DDD" solution?
  • How to get/set a property of an interface that is not always implemented
  • Read-only array field in unsafe struct
  • i got "Invalid attempt to call Read when reader is closed" when using sqldatareader how to solve it in a three
  • Why should I encapsulate objects in using if there is garbage collection
  • How to load Word document from byte array
  • Caliburn.Micro and ContextMenu for DataGrid Row
  • Linq "join" with a IList<T> getting "Error Unable to create a constant value.."
  • How to draw red wavy line under words in RichTextBox c# winform
  • HttpPostedFileBase returns Null MVC3
  • Refresh Dropdownlist in webform
  • How to convert serialized byte array back to its text form
  • How to do a loop to check all the variables at the same time for C#?
  • Facebook Sentiment Analysis API
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org