我正在尝试构建一个ASP.NET MVC 5 Web应用程序,该MyDatabase.mdf文件App_Data夹中包含一个文件.我安装了一个带有LocalDb实例的SQL Server 2014 Express .我可以使用服务器资源管理器编辑数据库表,但是当我调试应用程序并转到需要数据库的页面时,我收到以下错误.
建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称是否正确,以及SQL Server是否配置为允许远程连接.(提供程序:SQL网络接口,错误:50 - 发生本地数据库运行时错误.无法创建自动实例.请参阅Windows应用程序事件日志以获取错误详细信息.
所以我查看了下面的事件查看器Application,只反复看到一个警告.
为缓存压缩内容指定的目录C:\ Users\User1\AppData\Local\Temp\iisexpress\IIS临时压缩文件\ Clr4IntegratedAppPool无效.静态压缩正在被禁用.
所以我尝试重启服务器,仍然没有去.与以前相同的错误50.
我在一个Models叫做类的地方创建了一个类Post.
namespace MyApplication.Models
{
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
}
public class MyDatabase : DbContext
{
public DbSet<Post> Posts { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我还有一个Controller设置列出来自的帖子MyDatabase. …
我有一个List,有时它是空的或null.我希望能够检查它是否包含任何List项,如果没有,则将对象添加到List.
// I have a list, sometimes it doesn't have any data added to it
var myList = new List<object>();
// Expression is always false
if (myList == null)
Console.WriteLine("List is never null");
if (myList[0] == null)
myList.Add("new item");
//Errors encountered: Index was out of range. Must be non-negative and less than the size of the collection.
// Inner Exception says "null"
Run Code Online (Sandbox Code Playgroud) 尝试使用共享队列同时运行两个不同的函数并获得错误...如何使用共享队列同时运行两个函数?这是Windows 7上的Python 3.6版.
from multiprocessing import Process
from queue import Queue
import logging
def main():
x = DataGenerator()
try:
x.run()
except Exception as e:
logging.exception("message")
class DataGenerator:
def __init__(self):
logging.basicConfig(filename='testing.log', level=logging.INFO)
def run(self):
logging.info("Running Generator")
queue = Queue()
Process(target=self.package, args=(queue,)).start()
logging.info("Process started to generate data")
Process(target=self.send, args=(queue,)).start()
logging.info("Process started to send data.")
def package(self, queue):
while True:
for i in range(16):
datagram = bytearray()
datagram.append(i)
queue.put(datagram)
def send(self, queue):
byte_array = bytearray()
while True:
size_of__queue = queue.qsize()
logging.info(" queue size …Run Code Online (Sandbox Code Playgroud) 我试图在ASP.NET MVC 5应用程序中上传大小为5.25 MB的mp4视频文件.
我已经尝试将此添加到Web.config文件中,在大多数情况下,该文件已被接受为此问题.
<system.web>
<!-- This will handle requests up to 1024MB (1GB) -->
<httpRuntime maxRequestLength="1048576" />
</system.web>
Run Code Online (Sandbox Code Playgroud)
我也尝试在Web.config中设置超时
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
Run Code Online (Sandbox Code Playgroud)
但是,当我上传文件时,我得到了 System.Web.HttpException (0x80004005): Maximum request length exceeded.
也许有些东西需要在控制器或视图中设置?
控制器:
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
if (fileName != null)
{
var path = Path.Combine(Server.MapPath("~/Content/Videos"), fileName);
file.SaveAs(path);
}
}
return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)
视图:
@using (Html.BeginForm("Edit", "Posts", FormMethod.Post, new { enctype = "multipart/form-data" })) …Run Code Online (Sandbox Code Playgroud) 我想在用户单击按钮并且服务器正在处理某些数据时使用knockout.js禁用按钮.我正在看淘汰教程中的例子,但似乎缺少一些东西.
我enable:参与其中data-bind:
<body>
<form id="form1" runat="server" >
<h1 style="text-align: center">Select the item(s) you want.</h1>
<br />
<br />
<div id="buttons" style="text-align: center">
<button data-inline="true" data-bind="click: submit, enable: canSubmit" >Submit</button>
<button data-inline="true" data-bind="click: cancel">Cancel</button>
</div>
Run Code Online (Sandbox Code Playgroud)
我在视图模型中将observable设置为false.但是,初始化视图时,页面上会启用该按钮.所以我认为这是一个数据绑定问题.
function ViewModel() {
var self = this;
self.selectedItems = ko.observableArray([]);
// we should start off not being able to click the submit button
self.canSubmit = ko.observable(false);
};
Run Code Online (Sandbox Code Playgroud)
我希望启用该按钮,直到用户单击提交按钮,然后禁用它,直到服务器完成它为止.
self.submit = function () {
// disable submit button
self.canSubmit = …Run Code Online (Sandbox Code Playgroud) 我想根据值的不同,将用户发送到两个不同页面中的一个isCustomerEligible.当该变量的值设置为false时,它会调用Index但是然后返回视图Customer而不是视图Index.
public ViewResult Index()
{
return View();
}
public ViewResult Customer()
{
DetermineCustomerCode();
DetermineIfCustomerIsEligible();
return isCustomerEligible ? View() : Index();
}
Run Code Online (Sandbox Code Playgroud) 如何使用twitter bootstrap在模态窗口中显示进度条?屏幕灰显但模态对话框未显示.
的jsfiddle
http://jsfiddle.net/jkittell/L0ccmgf2/4/
HTML
<body>
<h1>Hello World!</h1>
<div class="modal hide" id="pleaseWaitDialog" data-backdrop="static" data-keyboard="false">
<div class="modal-header">
<h1>Processing...</h1>
</div>
<div class="modal-body">
<div class="progress progress-striped active">
<div class="bar" style="width: 100%;"></div>
</div>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
JavaScript的
$(function () {
var pleaseWait = $('#pleaseWaitDialog');
showPleaseWait = function () {
pleaseWait.modal('show');
};
hidePleaseWait = function () {
pleaseWait.modal('hide');
};
showPleaseWait();
});
Run Code Online (Sandbox Code Playgroud) 我有代码,我返回一个IWebElements列表及其相应的名称?我的理解是,具有两个项目的元组基本上是相同的,但是Dictionary使用哈希映射来关联这两个值.在字典上使用Two Item Tuple有什么好处,反之亦然?
public Dictionary<IWebElement, string> SelectAllOptions(IWebDriver driver, ref DataObject masterData)
{
//Get the ID of the dropdown menu
DatabaseRetrieval.GetObjectRepository(ref masterData);
var strDropMenuId = masterData.DictObjectRepository["ID"];
//Find the dropdown menu and pull all options into a list
try
{
var dropMenu = new SelectElement(driver.FindElement(By.Id(strDropMenuId)));
// TODO want to know how we want this list to return.
var options = dropMenu.Options as List<IWebElement>;
if (options != null)
{
var values = options.ToDictionary(option => option, option => option.Text);
return values;
}
}
Run Code Online (Sandbox Code Playgroud) 我已将MVC区域添加到现有的Web窗体项目中.我想在MVC项目的所有视图中使用母版页.我不明白我应该如何在MVC区域内引用WebForms的MasterPage.
我读过这两篇文章:
http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
http://www.eworldui.net/blog/post/2011/01/07/Using-Razor-Pages-with-WebForms-Master-Pages.aspx
我在controllers文件夹中添加了一个控制器扩展类.
public static class ControllerExtensions
{
public static ViewResult RazorView(this Controller controller)
{
return RazorView(controller, null, null);
}
public static ViewResult RazorView(this Controller controller, object model)
{
return RazorView(controller, null, model);
}
public static ViewResult RazorView(this Controller controller, string viewName)
{
return RazorView(controller, viewName, null);
}
public static ViewResult RazorView(this Controller controller, string viewName, object model)
{
if (model != null) controller.ViewData.Model = model;
controller.ViewBag._ViewName = GetViewName(controller, viewName);
return new ViewResult
{
ViewName = "RazorView",
ViewData …Run Code Online (Sandbox Code Playgroud) 如果给定一个特定的url,我有一个获取id和xpath的方法.如何通过请求传递用户名和密码,以便我可以抓取需要用户名和密码的网址?
using HtmlAgilityPack;
_web = new HtmlWeb();
internal Dictionary<string, string> GetidsAndXPaths(string url)
{
var webidsAndXPaths = new Dictionary<string, string>();
var doc = _web.Load(url);
var nodes = doc.DocumentNode.SelectNodes("//*[@id]");
if (nodes == null) return webidsAndXPaths;
// code to get all the xpaths and ids
Run Code Online (Sandbox Code Playgroud)
我应该使用Web请求获取页面源,然后将该文件传递给上面的方法吗?
var wc = new WebClient();
wc.Credentials = new NetworkCredential("UserName", "Password");
wc.DownloadFile("http://somewebsite.com/page.aspx", @"C:\localfile.html");
Run Code Online (Sandbox Code Playgroud) c# ×6
asp.net-mvc ×3
.net ×1
asp.net ×1
dictionary ×1
javascript ×1
jquery ×1
knockout.js ×1
list ×1
python-3.x ×1
razor ×1
sql-server ×1
tuples ×1