Best way to escape characters before jquery post ASP.NET MVC

I am a semi-newbie in ASP.NET MVC. I am creating an application that is used internally by my company.

The scenario is this: There are two Html.Listbox. One has all the information about the database, and the other is empty. The user will add items from the database list to the empty list.

Every time the user adds a command, I call the js function, which calls the ActionResult "AddCommand" in my EditController. In the controller, the selected items that have been added are saved in another database table.

Here is the code (it is called every time an element is added):

function Add (listbox) {...
   // skipping initialization code for urgency

var url = "/ Edit / AddCommand /" + cmd;

$ after (URL).

}

, , "cmd" - , "/", ":", "%", "?" .. ( )

, ? , .

, , , , "/", " [SLASH] Dogs" , "/".

, , - . .

+3
5

URI? POST, .

:

public ActionResult AddCommand(string cmd) { // ...

... :

var url = "/Edit/AddCommand";
var data = { cmd: cmd };
$.post(url, data);

... " " .

+4

"escape" ? , . .

function Add(listbox) { ...
//skipping initializing code for berevity

var url = "/Edit/AddCommand/" + escape(cmd);

$.post(url);

}
+3

javascript escaping, urlencoding.

Javascript

# .

function Add(listbox) { ...
//skipping initializing code for berevity

var url = "/Edit/AddCommand/" + escape(cmd);

$.post(url);

}
0

cmd escape()?

0

. , :

public virtual ActionResult AddCommand( string id )

:

public virtual ActionResult AddCommand( string cmd )

and then in your javascript call:

var url = "/Edit/AddCommand?cmd=" + cmd;

This way you do not have to worry about coding.

It would be best if you could pass in the identifier of the database item, not a string. This will probably be better for your db.

0
source

Source: https://habr.com/ru/post/1733557/


All Articles