to retreive data from database and insert into a form and also save it back

Posted by Prasanna64 under ASP.NET on 5/10/2012 | Points: 10 | Views : 1454 | Status : [Member] | Replies : 2
Helo alll,

Iam developing an application in asp.netmvc3 .I Had design the form in view using dhtml and give two buttons when we click one button it has to retreive from database and when we click another it has to save to databse.if any one knows send me the sample project




Responses

Posted by: Sekar.C on: 5/10/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
send your code lines

Regards
sekar.c

Regards
Sekar.c

Prasanna64, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prasanna64 on: 5/10/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
This is my controller code

public class HomeController : Controller
{
private JsonEntitiesModel dbContext;

protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
base.Initialize(requestContext);

if (this.Session[MyModule1.CONTEXT_KEY] != null)
{
this.dbContext = this.Session[MyModule1.CONTEXT_KEY] as JsonEntitiesModel;
}
else
{
throw new Telerik.OpenAccess.Exceptions.NoSuchObjectException(
"Cannot find ModelContext", null);
}
}




public ActionResult Index()
{


return View();
}

public ActionResult About()
{
return View();
}

public JsonResult Get()
{
var st = from i in dbContext.Usr_trainings
where i.Usr_training_id == 1
select new
{
Usr_training_id = i.Usr_training_id,
Usr_training_name = i.Usr_training_name,
Usr_training_duration = i.Usr_training_duration,
Usr_training_year = i.Usr_training_year,
Usr_training_comments = i.Usr_training_comments
};

return Json(st, JsonRequestBehavior.AllowGet);

}

}

This is my view file


@{
ViewBag.Title = "Home Page";
}

<h2>@ViewBag.Message</h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../../dhtmlxForm/codebase/skins/dhtmlxform_dhx_skyblue.css" />
<script type="text/javascript" src="../../dhtmlx/dhtmlx.js"></script>
<link rel="STYLESHEET" type="text/css" href="../../dhtmlx/dhtmlx.css" />


</head>

<body onload="doOnLoad()">
<div id="form_container" style="width:250px;height:300px;"></div>
<script type="text/javascript">
var myForm, formData;
function doOnLoad() {
formData = [
{ type: "fieldset", name: "data", label: "Welcome", inputWidth: "auto", list: [
{ type: "input", name: 'id', label: 'Id' },
{ type: "input", name: "Name", label: "Name" },
{ type: "input", name: "Duration", label: "Duration" },
{ type: "input", name: "Training year", label: "Training Year" },
{ type: "input", name: "comments", label: "Comments" },
{ type: "button", name: "submit", value: "submit", id:"submit"}]
}
]
myForm = new dhtmlXForm("form_container", formData);
}
</script>

</body>
</html>

<script type="text/javascript">
$(function(){


$("#display").click(function display(){

$.getJSON('/Home/Get', "", function (data) {

alert(data.Id);


myForm.setItemValue("id",data.Id);
myForm.setItemValue("Name", data.Name);
myForm.setItemValue("Duration", data.Duration);
myForm.setItemValue("Training Year", data.TrainingYear);
myForm.setItemValue("comments", data.Comments);




}
);
}

</script>

when i click submit the values are not loading

Prasanna64, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response