我正在使用MVC4和Entity Framework来开发Intranet Web应用程序.我有一个可以编辑的人员列表.当我访问编辑视图时,在文本框"开始日期"中,日期显示如下:7/11/2013 00:00:00.我想要做的是以yyyy/MM/dd格式显示它.我试过了,String.Format("{0:yyyy/MM/dd}", item.StartDate)但它不起作用.我也试过了注释,[DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")]但它也不起作用.
在我看来,我有这个:
<div class="editor-field">
@Html.TextBoxFor(model => model.StartDate, new { @class = "datepicker" })
@Html.ValidationMessageFor(model => model.StartDate)
</div>
Run Code Online (Sandbox Code Playgroud)
有什么想法怎么办?
我正在使用MVC 4和Entity Framework来开发Intranet Web应用程序.我有一个可以通过编辑操作修改的人员列表.我想通过使用模态表单使我的应用程序更具动态性.所以我试着把我的编辑视图放到我的Bootstrap模态中,我有两个问题:
我想我必须使用AJAX和/或jQuery,但我是这些技术的新手.任何帮助,将不胜感激.
编辑:我的索引视图:
@model IEnumerable<BuSIMaterial.Models.Person>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<br />
<div class="group">
<input type="button" value="New person" class="btn" onclick="location.href='@Url.Action("Create")';return false;"/>
<input type="button" value="Download report" class="btn" onclick="location.href='@Url.Action("PersonReport")';return false;"/>
</div>
@using (Html.BeginForm("SelectedPersonDetails", "Person"))
{
<form class="form-search">
<input type="text" id="tbPerson" name="tbPerson" placeholder="Find an employee..." class="input-medium search-query">
<button type="submit" class="btn">Search</button>
</form>
}
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Start Date</th>
<th>End Date</th>
<th>Details</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (BuSIMaterial.Models.Person item in ViewBag.PageOfPersons)
{
<tr>
<td>@item.FirstName</td>
<td>@item.LastName</td>
<td>@item.StartDate.ToShortDateString()</td> …Run Code Online (Sandbox Code Playgroud) 我有一个代表这样的字符串:
string startdatetime = "13988110600000"
Run Code Online (Sandbox Code Playgroud)
我想要做的是将此字符串(毫秒)转换为DateTime变量.这就是我正在做的事情:
double ticks = double.Parse(startdatetime);
TimeSpan time = TimeSpan.FromMilliseconds(ticks);
DateTime startdate = new DateTime(time.Ticks);
Run Code Online (Sandbox Code Playgroud)
结果几乎是好的:我有一个奇怪的约会,但时间还可以(30/04/0045 18:00:00).
这有什么理由吗?
我正在使用MVC4和实体框架来开发Web应用程序.我有一张表,列出了我在DB中的所有人员.对于他们每个人,我可以通过模态窗口编辑他们的信息,这是一个局部视图.但是,当我输入一些错误信息时,我的应用程序会将我重定向到我的部分视图.我想要做的是显示错误到我的模式窗口.
我的行动:
[HttpGet]
public ActionResult EditPerson(long id)
{
var person = db.Persons.Single(p => p.Id_Person == id);
ViewBag.Id_ProductPackageCategory = new SelectList(db.ProductPackageCategories, "Id_ProductPackageCategory", "Name", person.Id_ProductPackageCategory);
return PartialView("_EditPerson", person);
}
[HttpPost]
public ActionResult EditPerson(Person person)
{
ViewBag.Id_ProductPackageCategory = new SelectList(db.ProductPackageCategories, "Id_ProductPackageCategory", "Name", person.Id_ProductPackageCategory);
if (ModelState.IsValid)
{
ModelStateDictionary errorDictionary = Validator.isValid(person);
if (errorDictionary.Count > 0)
{
ModelState.Merge(errorDictionary);
return PartialView("_EditPerson", person);
}
db.Persons.Attach(person);
db.ObjectStateManager.ChangeObjectState(person, EntityState.Modified);
db.SaveChanges();
return View("Index");
}
return PartialView("_EditPerson", person);
}
Run Code Online (Sandbox Code Playgroud)
我的部分观点:
@model BuSIMaterial.Models.Person
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> …Run Code Online (Sandbox Code Playgroud) 我正在使用ASP.NET MVC 4和Entity Framework.在我的数据库中,我有一个表Subscription,表示对公共传输的订阅.这个订阅可以提供对几个公共交通公司的访问(因此订阅可能有1,2,3,...公司),然后这些表之间是多对多关系(我之间有一个中间表).
我想允许通过一个页面创建订阅,该页面将包含一个字段的订阅金额和可用的公司复选框.每个复选框代表一个现有公司(存储在我的数据库中的公司).
有关如何做到这一点的任何想法?我已经阅读了这个ASP.NET MVC多重复选框,但它并没有真正帮助.
编辑:这是我的表格图.

我正在使用ASP.NET MVC 4,我构建了这些ViewModel:
public class NotificationViewModel
{
public string GroupDesc { get; set; }
public bool AM { get; set; }
public bool PM { get; set; }
public int MaxNotif { get; set; }
}
public class SettingsViewModel
{
public List<NotificationViewModel> ListNotification { get; set; }
public SettingsViewModel()
{
ListNotification = new List<NotificationViewModel>();
}
}
Run Code Online (Sandbox Code Playgroud)
我的看法 :
@model PortailT2A.Models.SettingsViewModel
@{
ViewBag.Title = "Preferences";
Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
<h2>Preferences</h2>
@using(Html.BeginForm("Preferences", "Administrateur", FormMethod.Post))
{
<table id="settingsTable">
<tr>
<th>Groupe</th>
<th></th>
<th>AM</th>
<th>PM</th> …Run Code Online (Sandbox Code Playgroud) 我正在尝试从包含日期列的.xlsx电子表格导入数据.在这些列中,日期以DD-MON-YY格式显示(例如:20-AUG-12).
当我运行导入向导时,一切都很顺利,直到我必须精确列/字段映射.我有一个免责声明说所选格式与表字段定义不匹配(我的字段是日期字段).插入脚本的示例:
INSERT INTO simulation
(simulation_id,
simulation_name,
sim_start_date,
sim_end_date,
status,
last_run_date,
moddat,
modusr,
notification_email)
VALUES (251.0,
'Proposal Test',
To_date('01-DEC-11', 'DD-MON-YY'),
To_date('31-DEC-11', 'DD-MON-YY'),
'C',
To_date('09-AUG-12', 'DD-MON-YY'),
To_date('09-AUG-12', 'DD-MON-YY'),
'Brent Weintz',
'bweintz@carlsonwagonlit.com');
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此查询时,出现以下错误:
ORA-01843:无效月份01843. 00000 - "无效月份"
正如你所看到的,格式是匹配的,我无法弄清楚问题出在哪里......任何想法的人?
编辑:我的日期语言参数设置为"法语".我可以将其更改为"AMERICAN"吗?
我有一个应用程序,需要对某些字段进行一些验证.其中一个是姓氏,可以由2个单词组成.在我的正则表达式中,我必须接受这些空间,所以我尝试了很多东西,但我没有找到任何解决方案.
这是我的正则表达式:
@"^[a-zA-Zàéèêçñ\s][a-zA-Zàéèêçñ-\s]+$"
Run Code Online (Sandbox Code Playgroud)
在\s通常的空间,但它不工作,我得到这个错误信息:
parsing "^[a-zA-Zàéèêçñ\s][a-zA-Zàéèêçñ-\s]+$" - Cannot include class \s in character range.
Run Code Online (Sandbox Code Playgroud)
任何想法家伙?
我正在研究ASP.NET MVC4项目,我正在尝试使用SQL批量复制将数据从xlsx文件(Excel 2010文件)导出到我的数据库.我的Excel文件只包含2列:第一列包含数字(从1到25),第二列包含字符(连续系列"a,b,c")
这是我尝试导出数据的方法,但是我收到错误"数据源中String类型的给定值无法转换为指定目标列的int类型" :
public ActionResult Bulk()
{
string xConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\maarab\Documents\BulkCopy.xlsx;Extended Properties=Excel 12.0;";
using (OleDbConnection connection = new OleDbConnection(xConnStr))
{
OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection);
connection.Open();
string dbConnection = ((EntityConnection)db.Connection).StoreConnection.ConnectionString;
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
using (var bulkCopy = new SqlBulkCopy(dbConnection))
{
bulkCopy.DestinationTableName = "bm_test"
bulkCopy.WriteToServer(dr); //here I got the error
}
}
return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)
是什么导致这个错误?
我正在使用 ASP.NET MVC 4,我正在尝试获取上传文件的路径,以便打开和操作它。这就是我继续的方式:
控制器
public ActionResult Bulk(HttpPostedFileBase file)
{
FileStream fs = System.IO.File.Open(Server.MapPath(file.FileName),
FileMode.Open, FileAccess.Read);
return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)
看法
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm("Bulk", "Bulk", null, FormMethod.Post, new
{ enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<p>
<input type="file" name="file"/>
</p>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Create</button>
</div>
</fieldset>
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我收到一个错误,说... Could not find a part of the path ...
如何获取文件实际所在的路径?
c# ×9
asp.net-mvc ×6
ajax ×2
datetime ×2
jquery ×2
asp.net ×1
checkbox ×1
date ×1
excel ×1
file-upload ×1
filepath ×1
insert ×1
many-to-many ×1
oracle ×1
regex ×1
sql ×1
sqlbulkcopy ×1
viewmodel ×1