我是新来的MVC
.在我的应用程序中,我正在从Mydatabase中检索数据.但是当我运行我的应用程序时,它显示错误,这是我的网址
http://localhost:7317/Employee/DetailsData/4
Exception Details: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'k' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult DetailsData(Int32)' in 'MVCViewDemo.Controllers.EmployeeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Run Code Online (Sandbox Code Playgroud)
这是我的web.config文件代码
<connectionStrings>
<add name="EmployeeContext" connectionString="Server=.;Database=mytry;integrated security=true; ProviderName=System.Data.SqlClient"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
这是我的员工模型类(Employee.cs)
[Table("emp")] /* to map tablename with our class name*/
public class Employee
{
public int EmpId { get; set; }
public string Name …
Run Code Online (Sandbox Code Playgroud) 我有一个DropDown.我正在使用ng-repeat
Option 绑定它的值.我想仅使用值字段设置所选值.
这是我的代码.
<div ng-controller="myCtrl">
<select ng-model="selectedItemvalue">
<option value="">--Select --</option>
<option ng-repeat="sel in selectables" value="{{sel.value}}">{{sel.label}}</option>
</select>
<p>Selected Value is : {{selectedItemvalue}}</p>
</div>
Run Code Online (Sandbox Code Playgroud)
JS
angular.module('myApp', [])
// controller here
.controller('myCtrl', function($scope) {
$scope.selectables = [
{ label: 'A', value: 1},
{ label:'B', value: 2},
{ label: 'C', value: 3}
];
// this is the model that's used for the data binding in the select directive
// the default selected item
//using value, i want to set the selected value …
Run Code Online (Sandbox Code Playgroud) 我有两个表,tableA和tableB.
tableA有列:tabAId,col2,col3 (tabAId primaryKey和Identity列.)
tableB有列:tabAId,name (tabAId不为null)
我在tableA的hbm文件中创建了Bag,以维护关系.
<bag name="tableB" lazy="true" inverse="false"
batch-size="25" cascade="all-delete-orphan">
<key column="tabAId" />
<one-to-many class="tableB" />
</bag>
Run Code Online (Sandbox Code Playgroud)
当我尝试更新tableA中的记录时,它抛出异常,因为我在tableA实例中有子列表.
[NHibernate.Exceptions.GenericADOException] = {"无法删除集合:[MIHR.Entities.tableA.tableB#21] [SQL:UPDATE dbo.tableB SET tabAId = null WHERE tabAId = @ p0]"}
InnerException = {"无法将值NULL插入列'tabAId',表'SA_MIHR_DEV.dbo.tableB';列不允许空值.UPDATE失败.\ r \n语句已终止."}
我正在使用HttpClient向WebApi发出请求.
我写了这段代码
public async Task<string> ExecuteGetHttp(string url, Dictionary<string, string> headers = null)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (headers != null)
{
foreach (var header in headers)
{
client.DefaultRequestHeaders.Add(header.Key, header.Value);
}
}
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我从我的行动中调用这个方法.
public async Task<ActionResult> Index()
{
try
{
RestWebRequest RestWebRequest = new RestWebRequest();
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("Authorization", "bearer _AxE9GWUO__8iIGS8stK1GrXuCXuz0xJ8Ba_nR1W2AhhOWy9r98e2_YquUmjFsAv1RcI94ROKEbiEjFVGmoiqmUU7qB5_Rjw1Z3FWMtzEc8BeM60WuIuF2fx_Y2FNTE_6XRhXce75MNf4-i0HbygnClzqDdrdG_B0hK6u2H7rtpBFV0BYZIUqFuJpkg4Aus85P8_Rd2KTCC5o6mHPiGxRl_yGFFTTL4_GvSuBQH39RoMqNj94A84KlE0hm99Yk-8jY6AKdxGRoEhtW_Ddow9FKWiViSuetcegzs_YWiPMN6kBFhY401ON_M_aH067ciIu6nZ7TiIkD5GHgndMvF-dYt3nAD95uLaqX6t8MS-WS2E80h7_AuaN5JZMOEOJCUi7z3zWMD2MoSwDtiB644XdmQ5DcJUXy_lli3KKaXgArJzKj85BWTAQ8xGXz3PyVo6W8swRaY5ojfnPUmUibm4A2lkRUvu7mHLGExgZ9rOsW_BbCDJq6LlYHM1BnAQ_W6LAE5P-DxMNZj7PNmEP1LKptr2RWwYt17JPRdN27OcSvZZdam6YMlBW00Dz2T2dgWqv7LvKpVhMpOtjOSdMhDzWEcf6yqr4ldVUszCQrPfjfBBtUdN_5nqcpiWlPx3JTkx438i08Ni8ph3gDQQvl3YL5psDcdwh0-QtNjEAGvBdQCwABvkbUhnIQQo_vwA68ITg07sEYgCl7Sql5IV7bD_x-yrlHyaVNtCn9C4zVr5ALIfj0YCuCyF_l1Z1MTRE7nb");
var getCategories = await …
Run Code Online (Sandbox Code Playgroud) 我有一个while
循环,我有两个for
循环.我在最里面的for
循环中有一个条件.只要满足该条件,我想退出两个for
循环并继续while
循环:
while (1)
for x=1:20
for y=1:30
if(condition)
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
Matlab在Java中有类似标签的语句,还是有其他方法可以做到这一点?
我想忽略来自Json序列化的那些属性为null.为此,我在我的webapi.config
文件中添加了这一行.
config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore};
public static void Register(HttpConfiguration config)
{
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{identifier}",
defaults: new { identifier = RouteParameter.Optional }
);
config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling= DefaultValueHandling.Ignore };
}
Run Code Online (Sandbox Code Playgroud)
但它并没有忽略那些无效的财产.
这是我的班级
public class UserProfile
{
[JsonProperty("fullname")]
public string FullName { get; set; }
[JsonProperty("imageid")]
public int ImageId { get; set; }
[JsonProperty("dob")]
public Nullable<DateTime> DOB { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是Json从web api返回
{
"fullname": …
Run Code Online (Sandbox Code Playgroud) 在我的解决方案文件夹中有两个项目
API将服务于My Mvc web或android或IOS客户端的所有请求.
现在,我很困惑,我应该在哪里实施身份验证过程.
由于MVC身份使用基于Cookie的身份验证,因此API使用基于令牌的身份.
现在我想要什么在Web项目中,如果任何用户尝试打开仅供Authorize
用户使用的页面,如果他没有登录,那么他应该重定向到登录页面,并且当我将MVC身份时,它是可能的.
如果我将在API实施,那么我将如何在Web项目中管理cookie.
以及如何在从WEB到API的每个请求中发送该令牌
我试图在SQL Server中创建一个计算列.
这是创建列的脚本.
CREATE TABLE [dbo].[Invoice]
(
[ID] [int] IDENTITY(1,1) NOT NULL,
[InvoiceID] AS (('INV' + FORMAT(GETUTCDATE(), 'yyyyMMdd')) + RIGHT('000000' + CONVERT([VARCHAR](20), [ID]), (7))),
[Name] [nvarchar](50) NOT NULL,
[CreatedOn] [datetime] NOT NULL
CONSTRAINT [DF_Invoice_CreatedOn] DEFAULT (getutcdate())
) ON [PRIMARY]
GO
Run Code Online (Sandbox Code Playgroud)
它将为InvoiceId
列返回一个值,如下所示:
ID InvoiceID Name CreatedOn
--- -------------------- ------- -----------------------
1 INV201705090000001 amki 2017-05-09 13:11:06.790
2 INV201705090000002 amkit 2017-05-09 13:11:26.600
3 INV201705090000003 amkit3 2017-05-09 13:11:32.397
4 INV201705090000004 amkit6 2017-05-09 13:11:35.070
Run Code Online (Sandbox Code Playgroud)
但我想更多地修改它.
当服务器日期更改时,它再次从1开始.
这是我的预期输出.
ID InvoiceID Name CreatedOn
--- -------------------- …
Run Code Online (Sandbox Code Playgroud) 我有一个带有 Dockerfile 的 .Net 核心 Web 应用程序。
我正在使用 Azure DevOps 管道来构建 Docker 映像,并希望将该映像推送到 Docker Hub。
但是当我运行管道时,它在推送图像时失败并出现以下错误:
2019-07-25T07:40:39.2332684Z ##[section]Starting: Push an image
2019-07-25T07:40:39.2340807Z ==============================================================================
2019-07-25T07:40:39.2340932Z Task : Docker
2019-07-25T07:40:39.2341017Z Description : Build, tag, push, or run Docker images, or run a Docker command
2019-07-25T07:40:39.2341132Z Version : 0.154.1
2019-07-25T07:40:39.2341206Z Author : Microsoft Corporation
2019-07-25T07:40:39.2341308Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/docker
2019-07-25T07:40:39.2341405Z ==============================================================================
2019-07-25T07:40:39.4058071Z e6868ba4-0951-4724-b13b-58e178dacb79 exists true
2019-07-25T07:40:39.5494209Z [command]/usr/bin/docker push dockerDemo2019:19
2019-07-25T07:40:39.5780069Z The push refers to repository [docker.io/library/dockerDemo2019]
2019-07-25T07:40:40.5429692Z b0f339cf7b16: Preparing
2019-07-25T07:40:40.5430778Z a385a9a129e2: Preparing
2019-07-25T07:40:40.5431098Z 6339615de93e: …
Run Code Online (Sandbox Code Playgroud) 我需要为InvoiceID生成一列.我想像这样保持这个专栏的形式
INV0000001,
INV0000002,
.
.
.
.
INV0000010,
INV0000011,
.
. and so on.
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,此列随着最后一个索引而增加.我怎样才能做到这一点.
我正在使用SQL Server 2012.
我已经搜索过,但找不到,如何增加这样的数字.
c# ×5
asp.net ×3
asp.net-mvc ×3
sql ×2
sql-server ×2
angularjs ×1
azure-devops ×1
docker ×1
docker-image ×1
dockerhub ×1
hbm ×1
hibernate ×1
javascript ×1
jquery ×1
json ×1
loops ×1
matlab ×1
nhibernate ×1
t-sql ×1