I'm attempting to pass a string as a parameter for a controller in the URL of an AJAX call in a separate view. I want it to have the same nullable functionality as when you pass (int? id) in the controller, but instead be a string. Here's my code:
Separate View:
$.ajax({
url: "Save/"+string
}).done(function (data) {
$('body').append('<p>Query was successfully saved to the database.</p>');
});
Controller:
public ActionResult Save(string? data)
{
if(data == null)
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
return View(data);
}
and the view for Save has virtually nothing in it, I'm just trying to print the string that was passed.