简体   繁体   中英

With MVC, asp.net, is it possible to create a row with URL Query String?

For instance, I'd like to be able to send my.url/movie?title="a"&rating="b" and create a new row in the movie table with the appropriate data.

Is this possible?

One method I've attempted is creating movie.aspx which has movie.aspx.cs and movie.cs as well which can parse the information. Could I then send a post request with the relevant information, maybe?

I'm incredibly new to asp.net, mvc, and c#.

Certainly, in the controller that is fired with the example URL, build a handler for Movie that looks like this:

public ActionResult Movie(string title, string rating)
{
    // do your work here

    return View("SomeViewHere");
}

where SomeViewHere is the view you want to redirect to when you're done.

You can do this as Michael Perrenoud mentions , but I would strongly recommend against it. This opens you up to all kinds of attacks, including memory attacks where a malicious user could just hit permutations of words in your URL to pollute your database with millions and millions of rows in an effort to make it crash due to running out of space. I would highly recommend against this in any public-facing environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM