我觉得我一直在忽视这个强大的工具而不是将它用于满负荷.您最常使用的最有用的Visual Studio功能或工具是什么?
我有一个 API,我正在尝试使用 XUnit 对其进行一些集成测试。这是我的 API 控制器构造函数:
public class MyController : Controller
{
readonly IMyRepository _myRepository;
public MyController(IMyRepository myRepository)
{
_myRepository = myRepository;
}
public async Task<IActionResult> GetUser(Guid userId)
{
try
{
return Ok(await _my.GetUser(userId));
}
catch (Exception ex)
{
return StatusCode(500, "An error occurred while handling your request.");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的 API 控制器正在使用这个存储库:
public class MyRepository : IMyRepository
{
private string _connectionString;
public MyRepository(IConfiguration config)
{
_connectionString = config.GetConnectionString("DefaultConnection");
}
public async Task<User> GetUser(Guid userId)
{
using (SqlConnection con …Run Code Online (Sandbox Code Playgroud) I'm using Visual Studio 2008, and my database is SQL Server 2000.
I want to add a connection to the Server Explorer in VS. The Data source is Microsoft SQL Server (SqlClient). After entering in all my information and I click Test Connection, it is successful.
But when I click OK, I get the error:
Unable to add data connection. ExecuteScalar requires an open and available connection. The connection's current state is closed.
我正在尝试在我的视图页面上显示具有自定义文本值的下拉列表.
我正在尝试显示联系人列表.联系人包含ContactID,FirstName和LastName.
<%= Html.DropDownListFor(m => m.ContactId, new SelectList(Model.Contacts, "ContactID", "LastName"), "- Select a Contact -") %>
Run Code Online (Sandbox Code Playgroud)
现在我只是显示姓氏,但我想在下拉列表中显示名字和姓氏.
我有一个页面,您可以在其中查看酒店的信息.在此页面上有一个小表格来搜索您所在酒店页面的房间可用性.
<form id="form1" name="form1" action="search.asp" method="POST">
<input type="hidden" id="Hotel" name="Hotel" value="<%= HotelID %>">
Arrive: <input value="<% strURLBookingDate %>" type="text" id="ArrivalDate" name="ArrivalDate">
Depart: <input value="<% strURLBookingDate2 %>" type="text" id="DepartureDate" name="DepartureDate">
<input type="submit" name="btnHotelSearch" value="Search This Hotel">
<input type="submit" name="btnHotelSearchAll" value="Search All Hotels">
</form>
Run Code Online (Sandbox Code Playgroud)
但我还需要在表单上添加一个按钮,这样我点击它就可以搜索所有酒店.为此,我只需要在单击按钮时将名为"Hotel"的隐藏输入值设置为0.
当我点击btnHotelSearchAll时,如何在提交表单之前设置该隐藏值?
所以我有这个XML文档:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Item>
<URL>http://www.mysite.com/page?id=1</URL>
</Item>
</Root>
Run Code Online (Sandbox Code Playgroud)
当我尝试查看文档时,我收到一条错误消息:
XML解析错误:格式不正确
在=查询字符串中的符号.我尝试将=标志更改为%3D,但我得到了相同的错误%
我该怎么办?
我只是想创建一个表单,我可以在其中输入名称并上传文件.这是视图模型:
public class EmployeeViewModel
{
[ScaffoldColumn(false)]
public int EmployeeId { get; set; }
public string Name { get; set; }
public HttpPostedFileBase Resume { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的看法:
@using (Html.BeginForm("Create", "Employees", FormMethod.Post))
{
@Html.TextBoxFor(model => model.Name)
@Html.TextBoxFor(model => model.Resume, new { type = "file" })
<p>
<input type="submit" value="Save" />
</p>
@Html.ValidationSummary()
}
Run Code Online (Sandbox Code Playgroud)
我的控制器方法:
[HttpPost]
public ActionResult Create(EmployeeViewModel viewModel)
{
// code here...
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我发布到控制器方法时,Resume属性为null.Name属性传递得很好,但不是HttpPostedFileBase.
我在这里做错了吗?
可能重复:
根据内容调整iframe大小
我正在尝试将其中一个页面加载到iframe中.我不知道页面有多大,页面上的数据是动态加载的.我希望iframe始终适合页面,无论它有多大或多小.这就是我所拥有的:
function loadModal() {
myframe = $('<iframe id="mymodal" src="MyPage.aspx" width="700"></iframe>');
myframe.appendTo($('html'));
var height = document.getElementById('modalPreview').contentWindow
.document.body.scrollHeight;
$("#mymodal").attr("height", height);
}
Run Code Online (Sandbox Code Playgroud)
我一直试图在加载后获得页面的高度.问题是height回来了0.但如果我这样做:
setTimeout(function () {
$("#mymodal").attr("height", height);
}, 2000);
Run Code Online (Sandbox Code Playgroud)
加载正确的高度.我认为这是因为数据需要几秒钟才能加载.但是如果页面加载速度非常快,那么这看起来很时髦,或者如果加载页面的时间超过2秒,它仍然会给我0的高度.
有没有办法:
MyPage.aspx?我刚刚安装了SQL Server 2012 Web版本,我注意到此版本中的SQL Server Management Studio以前版本中没有很多选项.
简单的事情,例如右键单击表并选择"设计",或"编辑前200行"和"选择前1000行".
我需要安装其他东西吗?这些选项在其他地方吗?
我正在尝试水平显示无序列表.在每个列表项中,我有一个带有图像的锚标记,我想在列表项中垂直对齐显示.这是我的
HTML:
<ul>
<li>
<a href="#">
<img src="1.jpg" alt="" height="50" width="50" />
</a>
</li>
<li>
<a href="#">
<img src="2.jpg" alt="" height="50" width="50" />
</a>
</li>
<li>
<a href="#">
<img src="3.jpg" alt="" height="50" width="50" />
</a>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
CSS:
ul
{
margin: 0;
padding: 0;
list-style: none;
height: 93px;
}
ul li
{
display: inline-block;
width: 110px;
height: 93px;
text-align: center;
vertical-align: middle;
}
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
c# ×3
asp.net ×2
asp.net-mvc ×2
css ×2
html ×2
javascript ×2
sql-server ×2
.net ×1
asp.net-core ×1
encoding ×1
jquery ×1
unit-testing ×1
xml ×1
xunit ×1