i have a simple form on my page with a textbox and button that calls this javascript method
onclick="Create();"
and this is the function that is ran...
function Create() {
var txt = document.getElementById("longTxt").value;
if (txt == "Insert Name") {
alert("You must provide a name");
return;
}
var data = { Name: txt };
$.post("/Home/Create", data, null, "json");
}
The action called inserts the name into the database and returns a string.
The method works it adds the posted name to my database but how do i use that string my method returns to display the returned string in my textbox.
Edit:
what is my method suppose to look like i have something like
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult Create(string name)
{
string hash = repo.addName(name);
return new JsonResult()
{
Data = new { data = hash }
};
}
when i add breakpoints and check it out it looks like it is working it does add the name. the callback function is used because i replaced the
$("#longUrl").val(json.PropertyReturned);
with an alert(json.PropertyReturned); to see if anything is even happening and i get the textbox but it says "undefined"
im really new to all of this maybe im just doing the method and return wrong. also intelisense does not show "json.PropertyReturned" as an option when it pops up after typing "json."