0
我是新來的角js。我試圖將表單數據傳遞給操作,但它不起作用,它不會給我任何錯誤。請幫幫我。http post不能調用ASP.NET MVC動作
下面是我的js文件
var aboutmeApp = angular.module('aboutmeApp', ['ui.router']);
var configFunction = function ($stateProvider, $httpProvider, $locationProvider) {
$locationProvider.hashPrefix('!').html5Mode(true);
$stateProvider
.state('Default', {
url: '/',
views: {
"aboutmeview": {
templateUrl: 'Home/Home'
}
}
})
.state('Home', {
url: '/Home',
views: {
"aboutmeview": {
templateUrl:'/Home/Home'
}
}
})
.state('About', {
url: '/About',
views: {
"aboutmeview": {
templateUrl: '/Home/About'
}
}
})
.state('CV', {
url: '/CV',
views: {
"aboutmeview": {
templateUrl: '/Home/CV'
}
}
})
.state('Projects', {
url: '/Projects',
views: {
"aboutmeview": {
templateUrl: '/Home/Projects'
}
}
})
.state('Blog', {
url: '/Blog',
views: {
"aboutmeview": {
templateUrl: '/Home/Blog'
}
}
})
.state('Contact', {
url: '/Contact',
views: {
"aboutmeview": {
templateUrl: '/Home/Contact'
}
}
});
}
configFunction.$inject = ['$stateProvider', '$httpProvider', '$locationProvider'];
aboutmeApp.config(configFunction);
aboutmeApp.controller("ContactController", function ($scope,$http) {
$scope.alphabet = /^[A-z]+$/;
// $scope.emailaddress = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-][email protected][a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
$scope.submitForm = function() {
debugger
// check to make sure the form is completely valid
$http({
method: "POST",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
url: "/Home/Sendmail"
});
};
});
CSHTML文件
HTML
<--form name="myForm" ng-controller="ContactController" ng-class="{true:'error'}[submitted]" ng-submit="submitForm()">
<p class=" username">
<input type="text" name="user" ng-model="user" placeholder="NAME" required ng-pattern="alphabet" oninvalid="this.setCustomValidity('Please Enter UserName')" oninput="setCustomValidity('')" />
<label for="name">Name</label>
<span style="color:red" ng-show="myForm.user.$dirty && myForm.user.$invalid">
<span ng-show="myForm.user.$error.required">Username is required.</span>
</span>
<span style="color:red" class="error" ng-show="myForm.user.$error.pattern">
Alphabets only
</span>
</p><br />
<p class="mails">
<input type="email" name="email" id="email" ng-model="email" placeholder="EMAIL" required oninvalid="this.setCustomValidity('Please Enter Email')" oninput="setCustomValidity('')" style="background-color:white" />
<label for="mails">Email</label>
<span style="color:red" ng-show="myForm.email.$dirty && myForm.email.$invalid">
<span ng-show="myForm.email.$error.required">Email is required.</span>
<span ng-show="myForm.email.$error.email">Invalid email address.</span>
</span>
</p><br />
<p class="web">
<input type="text" name="web" id="web" placeholder="SUBJECT" />
<label for="web">Subject</label>
</p><br />
<p class="text">
<textarea name="text" placeholder="WRITE SOMETHING TO ME" />
</p><br />
<p class="submit">
<input type="submit" value="Send" ng-click="submitted=true" />
</p>
</form>
貴'submitForm'曾經執行?你對'$ http'的調用沒有指定任何數據,所以這就是爲什麼沒有數據發佈的原因。請參閱[文檔](https://docs.angularjs.org/api/ng/service/$http)。 – 2015-04-06 00:45:12
$ http調用沒有視圖的問題。 Sendmail操作不具有視圖(html頁面)。這樣http post就不會調用這個動作。我需要註冊不帶tempelateUrl的發送郵件動作。但我不知道該怎麼做。請幫幫我。 – 2015-04-12 23:04:20