Last active
August 29, 2015 14:00
-
-
Save fnalin/11389958 to your computer and use it in GitHub Desktop.
Demo Json Asp.Net MVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Controller | |
public class HomeController : Controller | |
{ | |
public ActionResult Index() | |
{ | |
return View(); | |
} | |
[HttpPost] | |
public bool PostJson(ModeloJson dados) | |
{ | |
return dados != null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//View | |
@{ | |
ViewBag.Title = "Index"; | |
} | |
<h2>EnviarJson</h2> | |
<button id="enviar">Enviar</button> | |
<script src="~/Scripts/jquery-1.10.2.min.js"></script> | |
<script> | |
$("#enviar").on("click", function () { | |
var dadosTeste = { "Code": "12345", "Id": "1677", "Notas": [{ "Nota": "1", "Inclusao": "28/4/2014"}, {"Nota": "2", "Inclusao": "28/5/2014" }] }; | |
var urlPost = "/Home/PostJson"; | |
$.ajax( | |
{ | |
type: 'post', | |
url: urlPost, | |
dataType: 'json', | |
contentType: "application/json; charset=utf-8", | |
data: JSON.stringify(dadosTeste), | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Class Model | |
public class ModeloJson | |
{ | |
public string Code { get; set; } | |
public string Id { get; set; } | |
public List<Notas> Notas { get; set; } | |
} | |
public class Notas | |
{ | |
public string Nota { get; set; } | |
public string Inclusao { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alterado p/ receber um List de Notas