@Html.DropDownListFor(m => m.branch, CommonMethod.getBranch("",Model.branch), "--Select--", new { @multiple = "multiple" })
@Html.DropDownListFor(m => m.division, CommonMethod.getDivision(Model.branch,Model.division), "--Select--", new { @multiple = "multiple" })
Run Code Online (Sandbox Code Playgroud)
我有两个DropDownListFor实例.我想为之前为Model.branch和Model.division存储的值设置为true.这些是存储的id的字符串数组
class CommonMethod
{
public static List<SelectListItem> getDivision(string [] branchid , string [] selected)
{
DBEntities db = new DBEntities();
List<SelectListItem> division = new List<SelectListItem>();
foreach (var b in branchid)
{
var bid = Convert.ToByte(b);
var div = (from d in db.Divisions where d.BranchID == bid select d).ToList();
foreach (var d in div)
{
division.Add(new SelectListItem { Selected …Run Code Online (Sandbox Code Playgroud) 我通过C#发送邮件时遇到异常
SmtpClient client = new SmtpClient()
Run Code Online (Sandbox Code Playgroud)
as System.Security.Cryptography.CryptographicException:句柄无效.
MailMessage mail = new MailMessage(from,to);
mail.To.Add(to);
mail.From = new MailAddress(from, "", System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = fr.message;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
//Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(from, Password);
client.Port = 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on …Run Code Online (Sandbox Code Playgroud) 我在MVC中使用UrlAttribute
但它不接受localhost网址,例如http:// localhost/GCWeb
[Url(ErrorMessage = "please_enter_valid_ftp_url", ErrorMessage = null)]
public string Url { get; set; }
Run Code Online (Sandbox Code Playgroud)
这会验证网址,但不会验证localhost网址.
我怎样才能做到这一点?
我们可以从剃刀下拉列表控件中选择多个项目吗?即为
@ Html.DropDownListFor(m => m.Country,CountryList as SelectList," - Select--")
asp.net asp.net-mvc html.dropdownlistfor razor asp.net-mvc-3
try
{
// throws IOException
}
catch(Exception e)
{
}
catch(IOException e)
{
}
Run Code Online (Sandbox Code Playgroud)
当try块抛出时IOException,它将调用第一个catch块而不是第二个块.任何人都可以解释这一点.为什么它会调用第catch一块?
我在数据库中有2个Field FromDate和ToDate.我希望结果LINQ查询具有2个日期的月差异和一些动态值的记录.
实际上我有一个数据库表作为EmploymentHistory,字段NameOfCompany为nvarchar(50),ProfileID为bigint,EmoploymentFrom为datetime,EmploymentUpto为datetime,IsCurrentEmployer为bit.
ProfileID是Profile的引用键我希望按月经验为所有配置文件生成查询.
如果IsCurrentEmployer为true,那么EmploymentUpto为null.