Model
public class Product
{
public string Name { get; set; }
public string college { get; set; }
}
Controller
public class HomeController : Controller
{
public ActionResult mypostview()
{
return View();
}
[HttpPost]
public JsonResult mypostview(Product product)
{
string a = product.Name;
string obb =("my Name is "+a+" and my college name is" +product.college);
return Json(obb, JsonRequestBehavior.AllowGet);
}
Html view
@{
ViewBag.Title = "mypostview";
}
<h2>mypostview</h2>
<div align="center">
<br />
<label>college Name</label>
<input id="btncollege" type="text" />
<br />
<input id="btnshow" type="button" value="send and receive" />
</div>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(function () {
$('#btnshow').click(function ()
{
var collegename = $("#btncollege").val();
var proc = {
Name: 'ritesh',
college: collegename
}
$.ajax({
type: 'POST',
dataType: 'json',
data: proc,
url: "/Home/mypostview",
success: function (data) {
alert("product name: " + data);
},
error: function (result) {
alert("Error in Operation");
}
});
});
});
</script>
No comments:
Post a Comment