Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a controller with a string input as parameter, how would i be able to call the controller from the browser, i tried it this:


[^]


but im getting the REsource cannot be found.

here is the controller:



C#
public string ReverseTheString(string input)
     {
         char[] arr = input.ToCharArray();
         Array.Reverse(arr);
         return new string(arr);
     }


What I have tried:

from AJAX calls to ASP.NET MVC action methods using jQuery[^]
Posted
Updated 21-Nov-16 10:32am

try like this
JavaScript
$.ajax({
           type: "POST",
           url: './ControllerName/ActionName',
           data: {},
           dataType: "json",
           async: true,
           success: function (result) {
               alert(result);
           }
       });

refer jQuery.ajax() | jQuery API Documentation[^]
 
Share this answer
 
Comments
forte74 21-Nov-16 12:16pm    
I mean by typing in the browser like http://localhost:58455/Home/ReverseTheString(%22abc%22)
Very very simple

if you have paste this code in home controller and ur iis is listening as http://localhost:54371 then it is

http://localhost:54371/Home/ReverseTheString/?input=test



interesting if you put a null string check like follows

public string ReverseTheString(string input)
      {
          if (string.IsNullOrWhiteSpace(input))
          {
              return "string is empty";
          }
          char[] arr = input.ToCharArray();
          System.Array.Reverse(arr);
          return new string(arr);
      }


then try this too



http://localhost:58455/Home/ReverseTheString/test




for multiple

public string ReverseTheString(string input, string input2, int age)
      {
          if (string.IsNullOrWhiteSpace(input))
          {
              return "string is empty";
          }
          char[] arr = input.ToCharArray();
          System.Array.Reverse(arr);
          return new string(arr);
      }


http://localhost:58455/Home/ReverseTheString/?input=first&input2=2nd&age=3
 
Share this answer
 
v4
Comments
forte74 23-Nov-16 20:25pm    
how would you call it , if you have multliple input parameters ?
Mohtshm Zubair 24-Nov-16 4:05am    
Plz mark the answer resolve

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900