我在我的MVC應用的控制器,其將數據插入數據庫中。這看起來像下面這樣:將值傳遞給控制器
public ActionResult Add(string orgCode)
{
ClientClass client = new ClientClass();
if (ModelState.IsValid)
{
int _records = client.Insert(orgCode, "");
// int _records = insertmodel.Insert(insertmodel.Org_Name, insertmodel.Org_Code);
if (_records > 0)
{
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Can Not Insert");
}
}
return View(client);
}
我也有我的視圖層的一些輸入字段,其存儲的NG-模型我的數據我輸入它看起來像這樣:
<div id="step-2" ng-controller="HomeController">
<div class="form-group">
<div class="form-group" style="padding-left:33%">
<div class="row">
<br />
<div class="col-lg-2">
<h2 style="color:#FF5D00">STEP 2:</h2>
</div>
<div class="col-lg-5">
<h2 style="color:#00386B"> Contact Details</h2>
</div>
</div>
<div class="row">
<div class="col-lg-2" style="padding-top:8px">
<label for="contactperson" class="labelQuestion">Contact Name</label>
</div>
<div class="col-lg-7">
<input type="text" class="form-control" name="contactperson" ng-model="userDetails.contactperson" id="txtContactPerson" placeholder="e.g John Smith">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="row">
<div class="col-lg-2" style="padding-top:8px">
<label for="contactemail" class="labelQuestion">Contact Email</label>
</div>
<div class="col-lg-7">
<input type="text" class="form-control" name="contactemail" ng-model="userDetails.contactemail" id="txtContactEmail" placeholder="e.g [email protected]">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="row">
<div class="col-lg-2" style="padding-top:8px">
<label for="contactnumber" class="labelQuestion">Contact Number</label>
</div>
<div class="col-lg-7">
<input type="text" class="form-control" name="contactnumber" id="txtContactNumber" ng-model="userDetails.contactnumber" placeholder="e.g +27 76 256 0098">
<div class="help-block with-errors"></div>
</div>
<button type="submit">submit stuff</button>
</div>
</div>
</div>
<pre>{{userDetails |json }} </pre>
{{message}}
</div>
在我的javascript,我測試,看看是否Angularjs綁定工作:
$scope.userDetails = { organisationname: '', organisationcode: '', branchcode: '', department: '', daterange: '', contactperson: '', contactemail: '', contactnumber: '' }
我所試圖做的是通過那些我山坳值lecting到這增加了該數據庫的方法。 4小時掙扎後,我很失落。我不知道從哪裏(JavaScript或從視圖)以及如何通過傳遞這些參數調用該方法。任何援助將不勝感激。