I am new to BreezeJS, and have recently created a project that is up and running. I am able to use Breeze to query data from my SQL server without a problem. However, whenever I try to save changes, the changes do not save. I have verified, in VS 2012, that the JavaScript save function is actually called, however the HttpPost method on the server side is never called.
Here is the Breeze Controller that I have set up:
using System.Linq;
using System.Web.Http;
using Newtonsoft.Json.Linq;
using Breeze.WebApi;
using FitnessTracker.Models;
namespace FitnessTracker.Controllers
{
[BreezeController]
public class BreezeController : ApiController
{
private readonly EFContextProvider<FitnessTrackerContext> _fitnessContext =
new EFContextProvider<FitnessTrackerContext>();
//
// GET: /Breeze/
[HttpGet]
public string Metadata()
{
return _fitnessContext.Metadata();
}
[HttpPost]
public SaveResult SaveChanges(JObject saveBundle)
{
return _fitnessContext.SaveChanges(saveBundle);
}
[HttpGet]
public IQueryable<FitnessEquipment> FitnessEquipments()
{
return _fitnessContext.Context.FitnessEquipments;
}
}
}
Here is the save function that I am using:
function saveChanges() {
return manager.saveChanges()
.fail(saveFailed);
}
Here is the HTML:
<div class="box-body form" data-bind="foreach: exercises">
<input type="text" class="txt-m g2" data-bind="text: EquipmentName" />
<input type="text" class="txt-m g1" data-bind="text: EquipmentLevel" />
<input type="text" class="txt-m g2" data-bind="text: DurationSeconds" />
<input type="text" class="txt-m g2" data-bind="text: Weight" />
<input type="text" class="txt-m g4" data-bind="text: DateTime" />
<br class="clear" />
</div>
Save Changes
Thanks in advance for your help!!
Edit 9/12/2013: I have fixed it thanks to Jay's help!!
The problem is that I was binding on the text instead of the value. I changed the html to:
<div class="box-body form" data-bind="foreach: exercises">
<input type="text" class="txt-m g2" data-bind="value: EquipmentName" />
<input type="text" class="txt-m g1" data-bind="value: EquipmentLevel" />
<input type="text" class="txt-m g2" data-bind="value: DurationSeconds" />
<input type="text" class="txt-m g2" data-bind="value: Weight" />
<input type="text" class="txt-m g4" data-bind="value: DateTime" />
<br class="clear" />
</div>
It is now saving without a problem. Thanks Jay for your help!