如何在C#和AngularJs中搜索记录! [英] How to search for a record in C# and AngularJs!
问题描述
大家好,
基本上我正在学习角度和C#.Net ..现在我开始明白了一点。
我创建了一个数据库,我在其中添加了来自用户输入的记录,如下所示:
Hi All,
Basically I am learning angular and C#.Net.. Which I am beginning to understand a little bit now.
I have crated a database in which I am adding records from the users input like so:
[HttpPost]
public HttpResponseMessage PostDs72(Persons p)
{
if (p == null)
return new HttpResponseMessage(HttpStatusCode.BadGateway);
PeopleContext db = new PeopleContext();
db.Persons.Add(p);
db.SaveChanges();
return new HttpResponseMessage(HttpStatusCode.Created);
}
上面代码中的
是添加或创建的代码的c#代码桌上人物的新人。
在事物的角度方面,这就是我所做的:
in the code above is the c# code that is adding or creating a new person in the table Persons.
And in angular side of things this is what I have done:
$scope.createPerson = function () {
$http({
method: 'POST',
url: '/api/Persons',
data: JSON.stringify($scope.newperson),
headers: { 'Content-Type': 'application/JSON' }
}).success(function (data) {
$scope.status = " Saved";
Getinfo();
}).error(function (error) {
$scope.status = 'Unabale to save ' + error.message;
});
};
这是创建新人的代码的角度。或者创造新人的功能
在我的HTML中这就是我所做的
this is the angular that code that is creating a new person. or function creating a new person
and in my HTML this is what I have done
<input type="text" name="FirsName" data-ng-model="newperson.FirstName" placeholder="Enter First Name" required />
<input type="text" name="LastName" data-ng-model="newperson.Last" placeholder="Enter Last Name" required />
<input class="search" type="button" value="Add Person" data-ng-show="DisplaySave" data-ng-click="createPerson()"
这是怎么回事我正在将人员添加到我的数据库中。
现在我被卡住了!如何通过搜索文本框中提供的姓氏继续搜索记录?可以帮助一些人吗?
如果这是windows表格,我会编写类似
And that is how I am adding people onto my database.
Now I am stuck! How do I go on in about search for record by their last name provided in a search textbox? can some one plsease help?
If this was windows forms I would code something like
SELECT * FROM Persons WHERE LastName = '"textbox1.text"'
现在当然这不是winsforms但有人可以提供帮助吗?
谢谢
now ofcourse this is not winsforms but is there anyone that can help?
Thank you
推荐答案
scope.createPerson = function(){
scope.createPerson = function () {
http({
method:' POST',
url:' / api / Persons',
data:JSON.stringify(
http({ method: 'POST', url: '/api/Persons', data: JSON.stringify(
scope.newperson),
header:{' Content-Type':' applicati on / JSON'}
})。success(function(data){
scope.newperson), headers: { 'Content-Type': 'application/JSON' } }).success(function (data) {
这篇关于如何在C#和AngularJs中搜索记录!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!