|
i have class User and my object have id
user.ID = 555
the user model have property
[ForeignKey("ID")]
public virtual IList<post> PostNames { get; set; }
i have class post :
public int IdUser { get; set; }
[ForeignKey("IdUser")]
public virtual User users { get; set; }
i get user.PostName - count = 0
and i know i have something in my database in post table.
What am I doing wrong ??
|
|
|
|
|
user.PostName - count = 0
Simple question. How can you substract a number from a string.
?????
|
|
|
|
|
Since you're using attributed mapping, you need to declare the type that you're mapping to. Your Post class is correct, but you need to change:
[ForeignKey("ID")]
public virtual IList PostNames { get; set; }
to
[ForeignKey("ID")]
public virtual ICollection<Post> PostNames { get; set; }
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
I am planning to automate a website (which is used to file tax). I think it is better to implement using asp.net. I am new to website automation. My questions are as follows,
1. How to make user to fill details in my asp page (User will enter details in my local server , and I will send those details to main website)
2. How to make user to enter captcha by showing him only image from main website in local page and later I will send that value to main website?
3. How to control child window from main window and vise versa using asp.net ?.
|
|
|
|
|
srikrishnathanthri wrote: How to make user to fill details in my asp page (User will enter details in my local server , and I will send those details to main website)
For this when user fills the details,you can make an HTTP POST to your main website.In this ,you can parse the parameters in your main website via an http post from your button click event handler when one clicks on the button after entering the details.
Here is a link
c# - HTTP request with post - Stack Overflow[^]
|
|
|
|
|
hi
I do not know where is going wrong but i seems not able to insert data using web api. Any help greatly appreciated and thanks a lot
The data
{"ID":1,"EmailAddress":"demo@demo.com"}
and the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Dapper;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace cirqer.Controllers.api
{
public class EmailListList
{
public int ID { get; set; }
public string EmailAddress { get; set; }
}
public class emaillistController : ApiController
{
static string connectionstring = ConfigurationManager.ConnectionStrings["CRConnectionString"].ConnectionString;
[HttpGet]
public Int16 EmailList_SelectCount()
{
try
{
using (var conn = new SqlConnection(connectionstring))
{
Int16 x = conn.ExecuteScalar<short>("EmailList_SelectCount", commandType: CommandType.StoredProcedure);
return x;
}
}
catch
{
return 0;
}
}
[HttpPost]
public void EmailList_Insert(EmailListList email)
{
try
{
// dynamic data = email;
using (var conn = new SqlConnection(connectionstring))
{
conn.Open();
conn.Execute("EmailList_Insert", email, commandType: CommandType.StoredProcedure);
conn.Close();
}
}
catch
{
}
}
}
}
|
|
|
|
|
Hello,
I have a form in which users can select "yes-full time", "yes-part time", "No" or "Retired"
In the code behind, I am trying to turn off validation for three textboxes and one radiobuttonlist if the user selects "No" or "Retired"
|
|
|
|
|
What is your question?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hello,
Thanks for the quick reply.
I am trying to have three textboxes and one radiobuttonlist have its requiredfieldvalidators disabled based on a previous radiobuttonlist.
My code behind is as follows:
------------
protected void rbCurrentlyEmployed_SelectedIndexChanged(object sender, EventArgs e)
{
if (rbCurrentlyEmployed.SelectedValue == "No" || rbCurrentlyEmployed.SelectedValue == "Retired" )
((RequiredFieldValidator)txtEmployer.FindControl("RFV_Employment_Employer")).Enabled = false;
((RequiredFieldValidator)txtJobTitle.FindControl("RFV_Employment_JobTitle")).Enabled = false;
((RequiredFieldValidator)txtWorkPhone.FindControl("RFV_Employment_WorkPhone")).Enabled = false;
((RequiredFieldValidator)rbgrantsmatchingfunds.FindControl("RFV_Employment_MatchingFunds")).Enabled = false;
else
{
((RequiredFieldValidator)txtEmployer.FindControl("RFV_Employment_Employer")).Enabled = true;
((RequiredFieldValidator)txtJobTitle.FindControl("RFV_Employment_JobTitle")).Enabled = true;
((RequiredFieldValidator)txtWorkPhone.FindControl("RFV_Employment_WorkPhone")).Enabled = true;
((RequiredFieldValidator)rbgrantsmatchingfunds.FindControl("RFV_Employment_MatchingFunds")).Enabled = true;
}
}
-----------------
I seem to be getting an error in the syntax of the 'else' statement.
ANY help would be greatly appreciated
|
|
|
|
|
You're missing the braces around the content of the if branch. As a result, only the first statement is considered part of the if branch - as if you had written:
if (rbCurrentlyEmployed.SelectedValue == "No" || rbCurrentlyEmployed.SelectedValue == "Retired" )
{
((RequiredFieldValidator)txtEmployer.FindControl("RFV_Employment_Employer")).Enabled = false;
}
((RequiredFieldValidator)txtJobTitle.FindControl("RFV_Employment_JobTitle")).Enabled = false;
((RequiredFieldValidator)txtWorkPhone.FindControl("RFV_Employment_WorkPhone")).Enabled = false;
((RequiredFieldValidator)rbgrantsmatchingfunds.FindControl("RFV_Employment_MatchingFunds")).Enabled = false;
else
{
((RequiredFieldValidator)txtEmployer.FindControl("RFV_Employment_Employer")).Enabled = true;
((RequiredFieldValidator)txtJobTitle.FindControl("RFV_Employment_JobTitle")).Enabled = true;
((RequiredFieldValidator)txtWorkPhone.FindControl("RFV_Employment_WorkPhone")).Enabled = true;
((RequiredFieldValidator)rbgrantsmatchingfunds.FindControl("RFV_Employment_MatchingFunds")).Enabled = true;
}
Add the braces, and the syntax error will go away:
if (rbCurrentlyEmployed.SelectedValue == "No" || rbCurrentlyEmployed.SelectedValue == "Retired" )
{
((RequiredFieldValidator)txtEmployer.FindControl("RFV_Employment_Employer")).Enabled = false;
((RequiredFieldValidator)txtJobTitle.FindControl("RFV_Employment_JobTitle")).Enabled = false;
((RequiredFieldValidator)txtWorkPhone.FindControl("RFV_Employment_WorkPhone")).Enabled = false;
((RequiredFieldValidator)rbgrantsmatchingfunds.FindControl("RFV_Employment_MatchingFunds")).Enabled = false;
}
else
{
((RequiredFieldValidator)txtEmployer.FindControl("RFV_Employment_Employer")).Enabled = true;
((RequiredFieldValidator)txtJobTitle.FindControl("RFV_Employment_JobTitle")).Enabled = true;
((RequiredFieldValidator)txtWorkPhone.FindControl("RFV_Employment_WorkPhone")).Enabled = true;
((RequiredFieldValidator)rbgrantsmatchingfunds.FindControl("RFV_Employment_MatchingFunds")).Enabled = true;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard,
Thank you for the quick reply.
I added the curly brackets as you suggested but I still get an error msg on the 'else' statement
My code behind is as follows now:
--------------
protected void rbCurrentlyEmployed_SelectedIndexChanged(object sender, EventArgs e)
{
if (rbCurrentlyEmployed.SelectedValue == "No" || rbCurrentlyEmployed.SelectedValue == "Retired" )
((RequiredFieldValidator)txtEmployer.FindControl("RFV_Employment_Employer")).Enabled = false;
((RequiredFieldValidator)txtJobTitle.FindControl("RFV_Employment_JobTitle")).Enabled = false;
((RequiredFieldValidator)txtWorkPhone.FindControl("RFV_Employment_WorkPhone")).Enabled = false;
((RequiredFieldValidator)rbgrantsmatchingfunds.FindControl("RFV_Employment_MatchingFunds")).Enabled = false;
}
else
{
((RequiredFieldValidator)txtEmployer.FindControl("RFV_Employment_Employer")).Enabled = true;
((RequiredFieldValidator)txtJobTitle.FindControl("RFV_Employment_JobTitle")).Enabled = true;
((RequiredFieldValidator)txtWorkPhone.FindControl("RFV_Employment_WorkPhone")).Enabled = true;
((RequiredFieldValidator)rbgrantsmatchingfunds.FindControl("RFV_Employment_MatchingFunds")).Enabled = true;
}
--------------------
After the textboxes, Visual Studio 12 indicates that the textboxes are a 'field' and are being used as a 'type'
ANY help would be greatly appreciated...
|
|
|
|
|
You are still missing the opening brace after the if statement. Use proper indentation of your code and it will become obvious.
|
|
|
|
|
Hi All,
I have three Action methods on in a Controller in ASP.Net MVC application and I have one cshtml page, cshtml page is using an AngularJS controller which in turn calls 2nd action method.
First Action method calls the View that is cshtml page that cshtml page calls the AngularJS controller which executes second Action method to get the data onto the cshtml page.
Data refreshing is working upto this.
Now the 3rd Action method which is inserting data into the database, when it is calling the first action method then the AngularJS code on the cshtml file is not executing to call the 2nd action method in the Controller.
Here is my View code (this part not refreshing so that I can have the latest data that's added)
@using MVCWithWebApiApp.Models;
@using System.Linq;
@model IEnumerable<MVCWithWebApiApp.Models.User>
@{
ViewBag.Title = "Users List";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Users List</title>
<script src="~/Scripts/jquery-2.2.4.min.js"></script>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/myApp.js"></script>
</head>
<body><br />
<div data-ng-app="myApp" data-ng-controller="userController">
<table style="border:none 0px gray;">
<tr>
<td>
<table style="border:solid 1px gray;">
<tr>
<td style="border:solid 1px gray;">User Id</td>
<td style="border:solid 1px gray;">User Name</td><br />
</tr>
<tr data-ng-repeat="usr in users">
<td><a href="/User/UpdateUser/{{usr.UserId}}"> {{usr.UserId}} </a> </td>
<td><a href="/User/UpdateUser/{{usr.UserId}}">{{usr.UserName}}</a></td><br />
</tr>
</table>
<pre>
</td>
<td>
@Html.ActionLink("Create User", "CreateUser")
</td>
</tr>
</table>
</body>
</html>
Here is my Controller code:
using MVCWithWebApiApp.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVCWithWebApiApp.Controllers
{
public class UserController : Controller
{
public ActionResult Index()
{
var dbContext = new MVCDBContext();
List<User> listOfUsers;
listOfUsers = dbContext.Users.ToList();
return View(listOfUsers);
}
public ActionResult GetUsers()
{
var dbContext = new MVCDBContext();
List<User> listOfUsers;
listOfUsers = dbContext.Users.ToList();
return Json(listOfUsers, JsonRequestBehavior.AllowGet);
}
public ActionResult CreateUser()
{<br />
return View();
}
[HttpPost]
public ActionResult CreateUser(FormCollection collection)
{
try
{
string Id = Request.Form["UserId"];
string UserName = Request.Form["UserName"];
int UserId;
var dbContext = new MVCDBContext();
User user = new User();
user.UserId = (int.TryParse(Id, out UserId) ? UserId : 0);
user.UserName = UserName;
dbContext.Users.Add(user);
dbContext.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
My Model is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MVCWithWebApiApp.Models
{
public class User
{
private int _userId;
public int UserId
{
get { return _userId; }
set { _userId = value; }
}
private string _userName;
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
}
}
And the .js file of the AngularJS code
var myApp = angular.module('myApp', []);
myApp.controller('userController', ['$scope', '$http', function ($scope, $http) {
$scope.users = "";
$http.get("/User/GetUsers")
.success(function (result) {
$scope.users = result;
})
.error(function (result) {
console.log(result);
});
}]);
Any help is going to be very very helpful thanks
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Are you getting any error in your .error {} in Angular. Did you check the console.
While debugging it doesn't hit the GetUsers action?
|
|
|
|
|
Hi,
Yes its giving me error but as below, can it help me please?
GET http:
And very interesting that the refresh is happening in Chrome browser but not in IE, how can I solve that type of problem?
Thanks buddy.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
I do not follow you.
is this the error GET http://localhost:1377/bundles/bootstrap ?
Can you explain a bit more.
|
|
|
|
|
When I tried to debug on Chrome Developer tools it was showing this line in red on the Console. That discrepancy is not happening on the Chrome browser.
Actually the discrepancy is happening on the IE browser. On Chrome its refreshing good, does AngularJS have any problem in executing on IE? or the Above line could be problem.
But when I try to check on IE Developers tools, it was saying error on DocumentType element, but there is actually no error there
And its showing warning for every element like more than one html element can't be there and more than one body element can't be there like that.
I am also not understanding why and this problem is happening only on IE not on Chrome.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Looks like you are missing the bundle. Can you check that you have the file in your project.
|
|
|
|
|
ASP.NET has become increasingly complex.
Webforms was the old but still valid technique.
MVC means you can stucture your application better and have more controll.
So is Web api a third technique or should I use it to create webservices and other things.
So my questions is:
Is Web Api a third technique to be used instead of webforms and MVC?
|
|
|
|
|
Web API is not a substitute for webforms or mvc, it is for creating APIs (ergo the name), or basically things that have no visual interface themselves, they are endpoints other apps can call to "do things".
|
|
|
|
|
Ok, thanks!
Kind of what I guessed.
Still a bit confusing that you can start a project as Web API I think.
Feels like you should start MVC and then Add Web API.
But I think I have to read more about it.
|
|
|
|
|
You might just be writing the API though and no front-end service. Even if your site does use API it is generally advised to keep the web api part in its own project anyway so you can enforce separation of concerns.
|
|
|
|
|
Ok, I see. Thanks!
By the way, do you know of any good MVC 5 tutorial?
I have tried some but they seem to get to comlicated to fast.
|
|
|
|
|
I used the "MVC Music Store" to get started with (just google it and you'll find it).
|
|
|
|
|