我的应用程序中使用了以下类型的URL.
本地主机/管理/ userdetail/ID
本地主机/管理/ userdetail/ID /真
本地主机/管理/ userdetail/ID /真/成功
这是我的管理员控制器
bool inSaveAction,字符串状态是可选的
[Authorize]
public ActionResult UserDetail(string Id, bool inSaveAction, string status)
{
}
[HttpPost, Authorize, ValidateAntiForgeryToken]
public ActionResult SaveUserDetail(UserDetailViewModel viewModel)
{
User userToSave = new User();
AdminService.UpdateUser(userToSave);
//This is calling the above function as it sending all 3 params
return RedirectToAction("UserDetail", new { Id = viewModel.Id,
inSaveAction = true, status = "success" });
}
Run Code Online (Sandbox Code Playgroud)
以下情况不起作用
@Html.ActionLink("DisplayName", "UserDetail", new { id = Model.Id })
Run Code Online (Sandbox Code Playgroud)
在Global.asax中
routes.MapRoute("UserDetail",
"UserDetail/{id}",
new
{
controller = …Run Code Online (Sandbox Code Playgroud) 使用ASP.Net webforms进行验证.
默认情况下,ASP.Net在根级别添加表单.这意味着我们只需要在表单中添加所有控件.
但是我需要定义需要验证的页面的一小部分,我使用了jQuery验证插件.
HTML
<html>
<body>
<form method="post" action="AssetDetails.aspx" id="Form1" enctype="multipart/form-
data">
//Other page content goes here. which doesnt require validation
<form class="form-horizontal" id="validation-form" method="get">
<div class="row-fluid">
<div class="widget-header header-color-blue2">
<h5>
Step 1</h5>
</div>
<input type="email" name="ctl00$MainContent$AssetTabs$DefineCriticality$email" id="email" class="span6" />
</div>
</form>
</form>
</body></html>
Run Code Online (Sandbox Code Playgroud)
使用Javascript
$(document).ready(function(){
alert($('#validation-form').length); // gives 0, because this form nested under
another form generated by ASP.Net
$('#validation-form').validate({
errorElement: 'span',
errorClass: 'help-inline',
focusInvalid: false,
rules: {
email: {
required: true,
email: true
}},
messages: {
email: …Run Code Online (Sandbox Code Playgroud) 我想在@ Url.Action方法中传递一个javascript变量作为路由参数.
我喜欢将screenmode javascript变量作为路由参数传递给我的action方法.
我有一个带有ScreenMode枚举属性的视图模型,基于它我应该在Ajax中调用一个动作.我还需要传递一个javascript变量作为路由的参数.
这是我尝试并得到编译错误.
当前上下文中不存在名称"screenMode"
$("#role-detail-form").submit(function (e) {
if ($(this).valid()) {
var screenMode = 0;
@{
if (Model.ScreenMode == UI.ViewModel.ScreenMode.New)
{
<text>
screenMode =2;
</text>
}
}
$.post('@Url.Action("SaveRoleDetail", new { mode=screenMode})',
$(this).serialize(), function (data) {
$("#role-detail").html(data);
$.validator.unobtrusive.parse($("#role-detail"));
});
}
e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
我的行动是
public ActionResult SaveRoleDetail(RoleModel viewModel, ScreenMode screenMode)
{
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用lambda表达式创建KeyValue对集合.
这是我的班级,下面是我的lambda代码.我没能创建KeyValuePair.
我想获得一部关于Id的KeyValuePair的集合,IsReleased用于 喜剧电影.我将这些KeyValuePair放在HashSet中以便快速搜索.
public class Movie{
public string Name{get;set;}
public int Id{get;set;}
public bool IsReleased{get;set;}
//etc
}
List<Movie> movieCollection=//getting from BL
var movieIdReleased= new
HashSet<KeyValuePair<int,bool>>(movieCollection.Where(mov=> mov.Type== "comedy")
.Select(new KeyValuePair<int,bool>(????));
Run Code Online (Sandbox Code Playgroud) 我有两个版本的工厂类基于该文章设计
http://www.oodesign.com/factory-pattern.html
public abstract class Employee
{
public string Name { get; set; }
protected string Role { get; set; }
public abstract string GetRole();
}
public class Manager : Employee
{
public Manager()
{
Role = "MGR";
}
public override string GetRole()
{
return this.Role;
}
}
Run Code Online (Sandbox Code Playgroud)
版本1:简单,违反开放式关闭原则
当我添加一个新的具体类时,每次都需要更改SimpleEmployeeFactory
public class SimpleEmployeeFactory
{
public static Employee GetEmployee(int typeId)
{
switch (typeId)
{
case 1:
return new Manager();
case 2:
return new TechnicalLead();
default:
return null; //if the id …Run Code Online (Sandbox Code Playgroud) 尝试使用JavaMail API从我的Gmail帐户发送电子邮件时,我在LogCat中收到以下错误消息.
11-09 11:04:14.385: W/System.err(18443): javax.mail.AuthenticationFailedException
11-09 11:04:14.385: W/System.err(18443): at javax.mail.Service.connect(Service.java:319)
11-09 11:04:14.385: W/System.err(18443): at javax.mail.Service.connect(Service.java:169)
11-09 11:04:14.385: W/System.err(18443): at javax.mail.Service.connect(Service.java:118)
11-09 11:04:14.385: W/System.err(18443): at com.srindroid.sendemail.MainActivity$RetrievedFeedTask.doInBackground(MainActivity.java:88)
11-09 11:04:14.385: W/System.err(18443): at com.srindroid.sendemail.MainActivity$RetrievedFeedTask.doInBackground(MainActivity.java:1)
11-09 11:04:14.385: W/System.err(18443): at android.os.AsyncTask$2.call(AsyncTask.java:288)
11-09 11:04:14.385: W/System.err(18443): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
11-09 11:04:14.385: W/System.err(18443): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
11-09 11:04:14.385: W/System.err(18443): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
11-09 11:04:14.385: W/System.err(18443): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
11-09 11:04:14.385: W/System.err(18443): at java.lang.Thread.run(Thread.java:841)
Run Code Online (Sandbox Code Playgroud)
源代码
package com.srindroid.sendemail;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress; …Run Code Online (Sandbox Code Playgroud) 我们正在尝试为我们的角度应用程序制作SonarQube代码覆盖率报告.我们使用Karma生成代码覆盖率报告并将其导入SonarQube分析器.
SonarQube已经为我们的项目提供了C#覆盖,现在我们也希望添加JavaScript代码覆盖.
Teamcity调用,Karma和它创建代码覆盖并将lcov文件和报告文件放入src\Planning.Spa\Coverage\report文件夹.
LCOV文件
TN:
SF:E:/a03/work/bb52cb33e083fc9/src/Planning.Spa/Offer/app/app.component.js
FN:5,(anonymous_1)
FN:6,AppComponent
FN:8,(anonymous_3)
FN:9,(anonymous_4)
Run Code Online (Sandbox Code Playgroud)
Teamcity具有以下MSBuild参数,用于生成C#代码覆盖率和JavaScript覆盖率.
SonarQube MSBuild配置
$sonar=%system.MSBUILD_SONARQUBE_RUNNER%\MSBuild.SonarQube.Runner.exe
begin /k:"com.test:Test" /n:"MyProject" /v:"%build.number%"
/d:sonar.cs.dotcover.reportsPaths="$coverageReport"
/d:sonar.cs.nunit.reportsPaths="$testResults"
/d:sonar.javascript.lcov.reportPaths="coverage\report\lcov.info"
Run Code Online (Sandbox Code Playgroud)
在运行SonarQube分析时,我们收到以下错误
[14:35:56][Step 13/13] 14:35:56.243 WARN: Could not resolve 114 file paths in
[E:\a03\work\bb52cb33e083fc9\src\Planning.Spa\coverage\report\lcov.info],
first unresolved path: E:/a03/work/bb52cb33e083fc9/src/Planning.Spa/Offer/app/app.component.js
Run Code Online (Sandbox Code Playgroud)
我们没有找到使用MSBuild runner运行C#和JavaScript的任何示例.也找不到任何与此相关的答案Could not resolve file paths
我们正努力让它在过去两周内发挥作用,但却找不到任何有用的示例或答案.类似的问题在这里和这里都没有答案
更新声纳分析更多信息
[14:35:43][Step 13/13] 14:35:43.751 INFO: Base dir: E:\a03\work\bb52cb33e083fc9\src\Planning.Spa
[14:35:43][Step 13/13] 14:35:43.751 INFO: Working dir: E:\a03\work\bb52cb33e083fc9\.sonarqube\out\.sonar\com.Planning_com.Planning_6CC487F0-8283-4351-9B65-F1698B1B804E
[14:35:43][Step 13/13] 14:35:43.755 INFO: Source paths: Offer/App/app.component.js, Offer/App/app.component.js.map, Offer/App/Common/order-by.pipe.js
[14:35:43][Step 13/13] 14:35:43.755 …Run Code Online (Sandbox Code Playgroud) 问题:
需要绑定具有Gender as enum属性的强类型模型.另外,我想显示资源文件中的显示文本.
我的模型是
public enum GenderViewModel
{
[Display(Name = "Male", ResourceType = typeof(Resources.Global), Order = 0)]
Male,
[Display(Name = "Female", ResourceType = typeof(Resources.Global), Order = 1)]
Female
}
Run Code Online (Sandbox Code Playgroud)
但它有点复杂,我无法纠正我的HTML,但我想要.
然后我从stackoverflow看一下简单易用的实现,将枚举传递给html.radiobutton for MVC3
并在cshtml中使用了HtmlHelper,如下所示
@Html.RadioButtonForEnum(m => m.Gender)
Run Code Online (Sandbox Code Playgroud)
HTML生成
<label for="_Gender_Male">
<input type="radio" value="Male" name="Gender" id="_Gender_Male"
data-val-required="Gender is required" data-val="true" checked="checked">
<span class="radiotext">Male</span>
</label>
<label for="_Gender_Female">
<input type="radio" value="Female" name="Gender" id="_Gender_Female">
<span class="radiotext">Female</span></label>
Run Code Online (Sandbox Code Playgroud)
它非常简单,对我来说效果很好.但我没有从资源文件中获取值.我的应用程序是多语言的,我使用全局资源文件来提供不同的语言支持.
问题:
男性显示应该是男性和女性显示应该是Kvinna应该来自资源文件,因为我目前的文化是sv-se
任何人都可以帮助/提供一个可以很好地控制HTML的简单解决方案吗?
我正在研究一个系列.我需要从集合中删除一个项目并使用过滤/删除的集合.
这是我的代码
public class Emp{
public int Id{get;set;}
public string Name{get;set;}
}
List<Emp> empList=new List<Emp>();
Emp emp1=new Emp{Id=1, Name="Murali";}
Emp emp2=new Emp{Id=2, Name="Jon";}
empList.Add(emp1);
empList.Add(emp2);
//Now i want to remove emp2 from collection and bind it to grid.
var item=empList.Find(l => l.Id== 2);
empList.Remove(item);
Run Code Online (Sandbox Code Playgroud)
问题是甚至在删除项目后我的收藏仍显示计数2.
可能是什么问题?
编辑:
原始代码
var Subset = otherEmpList.FindAll(r => r.Name=="Murali");
if (Subset != null && Subset.Count > 0)
{
foreach (Empl remidateItem in Subset )
{
Emp removeItem = orginalEmpList.Find(l => l.Id==
remidateItem.Id);
if (removeItem != …Run Code Online (Sandbox Code Playgroud) 我不确定为什么jquery验证在属性可以为空时触发int?并且没有标记任何数据注释属性.它的asp.net MVC 4应用程序
public class MyViewModel{
public int? ResourceId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
MyView.cshtml
@model MyViewModel
@Html.DropDownListFor(m => m.ResourceId,
((IEnumerable<SelectListItem>)ViewData["resourceLookup"]),"--Select--")
Run Code Online (Sandbox Code Playgroud)
生成的HTML
<select data-val="true" data-val-number="The field ResourceId must be a number."
id="ResourceId" name="ResourceId">
<option value="">--Select--</option>
<option value="1">Type 1</option>
</select>
Run Code Online (Sandbox Code Playgroud)
此选择框是可选的.用户可以忽略它.但是,当他们忽略我收到错误消息The field ResourceId must be a number.
在Global.asax.cs中,我尝试设置AddImplicitRequiredAttributeForValueTypes属性以防止将data-*属性添加到不需要的字段.但正如名称所说,它只能阻止添加data-required-*属性.
protected void Application_Start()
{
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes=false;
}
Run Code Online (Sandbox Code Playgroud)
如何在此处阻止数据类型检查属性(data-val-number)?
编辑:
尝试设置DataType也没用,仍然有同样的问题.看起来这不会被应用,<select>并且可能仅适用于<input>和设置type="text"
[DataType(DataType.Text)]
public int? ResourceId { get; set; }
Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc jquery jquery-validate unobtrusive-validation
c# ×5
asp.net-mvc ×4
asp.net ×2
jquery ×2
razor ×2
android ×1
collections ×1
html ×1
istanbul ×1
jakarta-mail ×1
javascript ×1
keyvaluepair ×1
lambda ×1
list ×1
refactoring ×1
sonarjs ×1
sonarqube ×1
url-routing ×1