我真的不知道我做错了什么.我希望我的文本框与我的按钮大小相同.我已经尝试过在cshtml中进行了很多更改,但没有成功.

在我的cshtml文件下面:
@model SomeModel.Models.LoginViewModel
<div class="row">
<div class="col-md-8 col-sm-12 col-xs-12">
<section id="loginForm">
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<hr />
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
<div class="col-md-12">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.UserName)
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
<div class="col-md-12">
@Html.PasswordFor(m => …Run Code Online (Sandbox Code Playgroud) Web API 2中的文件上载问题
虽然我上传文件与表格发布此工作文件,但我发送来自Rest Client的相同信息,如Google Chrome中的Postman或使用Android或iOS应用程序发布文件信息Web Api 2代码未检测到文件multipart/form-post
以下是我的HTML代码
<form enctype="multipart/form-data" method="post" action="/api/feedback">
<input type="text" name="Scope" placeholder="Scope" value="feedback">
<input type="text" name="Lang" placeholder="Lang" value="en">
<input type="text" name="Collection" placeholder="Collection" value="7b22437573746f6d65724964223a392c2253657276696365526571756573744964223a312c224174746974756465223a332e322c22576f726b457468696373223a342e322c2248796769656e65223a352c22416d6f757450616964223a333132332e327d">
<input type="file" name="Photo1" placeholder="Photo1">
<input type="file" name="Photo2" placeholder="Photo2">
<input type="file" name="Signature" placeholder="Signature">
<input type="submit" value="Submit">
</form>
Run Code Online (Sandbox Code Playgroud)
这个.Net Web Api 2代码
public async Task<Result> Post()
{
var model = new ApiData();
var result = new Result();
if (Request.Content.IsMimeMultipartContent())
{
try
{
string root = HttpContext.Current.Server.MapPath("~/assets/temp");
var provider = new MultipartFormDataStreamProvider(root);
var sb = …Run Code Online (Sandbox Code Playgroud) 在我的MVC 5应用程序中,我的DeleteConfirmedActionResult中有一个try-catch块,效果很好.因此,我不重复代码,我试图将下面代码块的指示部分放入控制器外部的函数中.我将该函数添加到自定义ErrorLog类中,但是当我这样做时,Intellisense指出"System.Web.MVC.ModelState没有IsValid的定义".
此链接指示错误来自尝试使用ModelState类而不是属性.但是,该文章没有说明应该做什么.
下面是我目前所遵循的代码.我的问题是我需要做些什么,以便我可以将该ErrorLog条目保存到我的数据库表中?
这是我控制器中的代码
catch (Exception e)
{
var _e = new ErrorLog().FillAndSend(e, "Delete", "ChildActionNames");
// The following is identical each time I use this catch(Exception e) block
UnitOfWorkErrorLog uw = new UnitOfWorkErrorLog();
if (ModelState.IsValid)
{
uw.ErrorLogRepository.Insert(_e);
uw.Save();
return View("ErrorManaged");
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我想要做的事: 在控制器中捕获块
catch (Exception e)
{
var _e = new ErrorLog().FillAndSend(e, "Delete", "ChildActionNames");
_e.SaveAlert(_e); // pass ErrorLog instance to SaveAlert function
}
Run Code Online (Sandbox Code Playgroud)
功能现在在ErrorLog课堂上
public void …Run Code Online (Sandbox Code Playgroud) 我有以下代码,只有第一个表单提交任何内容,以下提交null值,每个模型都有数据.如果我将其更改为一个大表单,则所有内容都会提交.为什么其他个人形式会发布空值?
视图
@model myModel[]
<ul>
@for (int i = 0; i < Model.Length; i++)
{
using (Html.BeginForm("controllerAction", "Controller", FormMethod.Post,
new { id="Form"+i }))
{
<li>
@Html.TextBoxFor(a => a[i].property1)
@Html.CheckBoxFor(a => a[i].property2)
@Html.HiddenFor(a => a[i].property3)
<input type="submit" />
</li>
}
}
</ul>
Run Code Online (Sandbox Code Playgroud)
调节器
[HttpPost]
public ActionResult controllerAction(myModel[] models)
{
...do stuff...
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个Web应用程序,我有一个带有三种动作方法的Home控制器; 索引,关于,联系.现在要访问About操作方法我需要键入以下url https://servername/home/about所以我的问题是我是否可以访问About操作方法而不引用"Home"控制器类.如"http://servername/About/"感谢,问候
所以我试图运行一个类似于SQL查询的Linq查询:
SELECT COUNT(*)
FROM table
WHERE ww >= [wwStartSelected]
AND ww <= [wwEndSelected]
AND manager='[managerName]'
AND status='Done'
GROUP BY ww;
Run Code Online (Sandbox Code Playgroud)
获取给定ww范围内的行数(任务)的计数,这些行被标记为在特定管理器下完成并按ww分组.我试图创建一个返回类似的LINQ查询(wwStartSelected && wwEndSelected是全局变量):
protected List<int> getManagerDoneCount(string managerName)
{
using (var context = new InfoDBContext())
{
List<int> managerDoneCount = context.InfoSet.Where(x => x.ww >= wwStartSelected && x.ww <= wwEndSelected && x.manager == managerName && x.status == "Done").GroupBy(x => x.ww).Count().ToList();
return managerDoneCount;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,此查询将输入图表:
var testChart = new Chart(width: 600, height: 400)
.AddTitle("Test")
.AddSeries(
name: "Done",
chartType: "StackedColumn100",
xValue: new[] { WWList …Run Code Online (Sandbox Code Playgroud) 我已经尝试了很多答案,并与结论没有甚至开发商自己,我有得到由一个复杂的模块中创建一个索引页答案出来了,视图接收与ActionAsPdf模块,并产生除了当页的PDF打破表继续在下一页覆盖表头顶部的记录.
public ActionResult PrintRoster(Guid id)
{
string footer = "--footer-right \"Date: [date] [time]\" " + "--footer-center \"Page: [page] of [toPage]\" --footer-line --footer-font-size \"9\" --footer-spacing 5 --footer-font-name \"calibri light\"";
return new ActionAsPdf("RosterPDF",
new { id = id }) { FileName = "ClassRoster.pdf",
PageSize = Rotativa.Options.Size.A4,
PageOrientation = Rotativa.Options.Orientation.Portrait,
MinimumFontSize = 16,
PageMargins = {Top = 15, Bottom = 22},
PageHeight = 40,
CustomSwitches = footer
};
}
Run Code Online (Sandbox Code Playgroud)
创建RosterPDF然后生成有问题的PDF
@model Training.ViewModels.RosterViewModel
@using Training.UtilModels
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head> …Run Code Online (Sandbox Code Playgroud) 我需要在MVC5中创建一个GridView来查看数据,还需要添加一些下拉列表来过滤数据并在GridView中显示结果.我无法在MVC中找到Grid视图的任何好例子.我应该使用GridView还是只是尝试使用Table?以及如何找到一个关于它的好教程?感谢帮助.
我有一个部分视图,可以更改连接字符串.提交Edit动作时会被调用.从这里我想要返回并重新打开局部视图,如果我希望用户有第二次去.如果一切顺利(或崩溃),我想调用我的JavaScript函数Logout,将用户注销并重定向到某个起始页.
两种解决方案都有效,但不是一起 我显然错过了一些最佳实践,我该怎么办?
部分视图:EditSetting
@model WebConsole.ViewModels.Setting.SettingViewModel
@using (Ajax.BeginForm("Edit", "Setting", new AjaxOptions { UpdateTargetId = "div" }, new { id = "editform" }))
{
<fieldset>
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new {@class = "text-danger"})
<div class="form-group">
@Html.LabelFor(model => model.User, htmlAttributes: new {@class = "control-label col-md-2"})
<div class="col-md-10">
@Html.EditorFor(model => model.User, new {htmlAttributes = new {@class = "form-control"}})
@Html.ValidationMessageFor(model => model.User, "", new {@class = "text-danger"})
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Password, htmlAttributes: new {@class = "control-label …Run Code Online (Sandbox Code Playgroud) javascript asp.net-mvc asp.net-mvc-partialview asp.net-mvc-5
我在ASP.NET MVC 5项目中使用JQueryUI Datepicker.我希望用户在"创建"和"编辑"视图中以mm/dd/yy格式输入日期.这是我迄今为止所取得的成就:
这是我的模特:
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString =
"{0:MM-dd-yyyy}",
ApplyFormatInEditMode = true)]
public DateTime ProjectDeadline { get; set; }
Run Code Online (Sandbox Code Playgroud)
这是_Layout.cshtml中的jQuery代码:
<script type="text/javascript">
$(function () {
$('.date-picker').datepicker({ dateFormat: "MM-dd-yy" });
})
</script>
Run Code Online (Sandbox Code Playgroud)
如果我没有在编辑中触摸日期并点击保存,我会收到警告:
ProjectDeadline字段必须是日期.
我尝试了许多可能性来获得我想要的东西,但这是我能得到的最好的东西.我在大多数尝试中都遇到了错误.你能告诉我如何修复我的代码以正确地在日期字段中获取mm/dd/yyyy格式吗?谢谢.
asp.net-mvc-5 ×10
asp.net-mvc ×8
c# ×3
asp.net ×2
css ×1
date ×1
gridview ×1
html-to-pdf ×1
javascript ×1
jquery ×1
linq ×1
razor ×1
rotativa ×1