我正在使用RegularExpressionAttribute验证属性.该物业需要允许anything but zero length string, null, or (just) spaces.我正在使用的正则表达式是"^(?!^ *$)^.+$".
如果值为null或an empty string,则RegularExpressionAttribute.IsValid始终返回true但我认为它应该为false(只有空格才能正常工作).
我不是正则表达式专家,但我相信表达式是正确的(如果我使用Regex.IsMatch空字符串直接从我的代码验证正则表达式返回false - 如预期的那样).这是RegularExpressionAttribute的问题吗?
(我知道在这种情况下,RequiredAttribute通常是一个快速但不是一个选项)
更新:
为了消除任何歧义,这里有一小段测试代码来演示:
public class MyValueTester
{
// internal const string _REGEX_PATTERN = "^(?!\\s*$).+$";
// internal const string _REGEX_PATTERN = @"^(?!\s*$)";
internal const string _REGEX_PATTERN = @"[^ ]";
public MyValueTester()
{
ProperValue = "hello";
NullValue = null;
SpaceValue = " ";
LeadingSpaceValue = " hi";
EmptyValue = "";
}
[RegularExpression(_REGEX_PATTERN, …Run Code Online (Sandbox Code Playgroud) 在阅读https://softwareengineering.stackexchange.com/questions/165444/where-to-put-business-logic-in-mvc-design/165446#165446后,我仍然对要将代码放置在何处感到困惑计算折扣。我认为计算产品或服务的折扣价绝对是业务逻辑的一部分,而不是应用程序路由或数据库交互的一部分。因此,我正在努力将业务逻辑放在何处。
例
class Model
{
public function saveService($options)
{
$serviceId = $options['service_id'];
//Model reads "line Item" from database
$service = $this->entityManager->find('Entity\ServiceLineItem', $serviceId);
//uses the data to compute discount
//but wait.. shouldn't model do CRUD only?
//shouldn't this computation be in Controller?
$discount = ($service->getUnitPrice() * 0.25);
// Add the line item
$item = new SalesItem();
$item->setDiscount($discount);
}
}
class Controller
{
function save()
{
$this->model->saveService($options);
}
}
Run Code Online (Sandbox Code Playgroud)
题:
在$discount计算之上,它应该留在模型中还是应该留在Controller中?如果进入控制器,则控制器必须先调用$service(通过模型),然后$discount在控制器内部进行计算,然后将其值发送回要保存的模型。那是这样做的方式吗?
注意
我可能会将模型与“存储”混淆。我可能需要一个执行业务逻辑的模型,而数据库/持久性存储应该是一个单独的层。
我想创建在开始时将被禁用或不可见的文本区域。有一个下拉列表,用于选择最后一个选项,即其他选项,它应启用或使文本区域可见,并采用该值并在提交时传递给控制器。
我无法显示正确的分钟格式.只有第一个分钟数(fe:17:0for 17:00和14:3for 14h03)
格式出了什么问题?
我的看法:
<td>
@Html.DisplayFor(modelItem => item.HeureEvenement.Hour):@Html.DisplayFor(model => item.HeureEvenement.Minute)
</td>
Run Code Online (Sandbox Code Playgroud)
我的模特:
[Column("HEURE_EVENEMENT")]
[Required]
[Display(Name = "Heure de début: ")]
[DataType(DataType.Time)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "HH:mm tt")]
public DateTime HeureEvenement { get; set; }
Run Code Online (Sandbox Code Playgroud) 如果我在这样的文件中设置一些常量:
'use strict';
angular.module('balrogApp.config', [])
.constant('balrogConfig', {
'backend': 'http://127.0.0.1:8000/api/catalog',
'authenticatedUser': 1
});
Run Code Online (Sandbox Code Playgroud)
如何从控制器访问它?:
'use strict';
angular.module('balrogApp.header', ['balrogApp.config'])
.controller('headerController', ['balrogConfig', function ($location, Users, balrogConfig) {
this.usersList = Users.query();
this.currentUser = balrogConfig.authenticatedUser;
/* ... */
}])
Run Code Online (Sandbox Code Playgroud)
这种方式适用于工厂,但不适用于控制器.那么如何正确导入和使用我的常数呢?
另外,有没有办法从视图中设置常量?
基本上,我想authenticatedUser在认证后设置适当的值(从输入模型的视图中检索)并能够从任何控制器访问它.
我遇到这个错误,而持续主动迁移是我的问题.谷歌也试图解决这些问题.但解决方案并没有解决我的问题.
我怎么解决这个问题?
PM> Enable-migrations
System.Runtime.Serialization.SerializationException: Type is not resolved for member 'System.Data.Entity.Migrations.Design.ToolingFacade+GetContextTypeRunner,EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.GetContextType(String contextTypeName)
at System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String contextTypeName)
at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Type is not resolved for member 'System.Data.Entity.Migrations.Design.ToolingFacade+GetContextTypeRunner,EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Run Code Online (Sandbox Code Playgroud) 我有以下型号患者类:
public class Patient
{
public int PatientID { get; set; }
public virtual Salutation salutation { get; set; }
public int SalutationID { get; set; }
public string Surname { get; set; }
public string Firstname { get; set; }
[Display(Name = "Date of Birth")]
[DisplayFormat(DataFormatString="{0:d}", ApplyFormatInEditMode=true)]
public DateTime DOB { get; set; }
public string RegNo { get; set; }
public DateTime RegDate { get; set; }
public string Occupation { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
VatalSigns类
public class …Run Code Online (Sandbox Code Playgroud) 我得到的不应该在视图中ping数据库...但是想知道正确的解决方案.在我的一个观点中,我需要根据每个孩子提取一个@order孩子的信息items,以及Amount另一个模型item.像这样的东西:
<% @order.items.each do |item| %>
<td><%= item.name %></td>
<td><%= Refund.where(item_id:item.id).first.amount %></td>
<td><%= Amount.where(item_id: item.id).first.amount %></td>
<% end %>
Run Code Online (Sandbox Code Playgroud)
为了避免视图中的db命中,我想到的唯一解决方案是在控制器中创建所有相关数据的大量哈希值,然后从视图中访问它.所以它会是这样的:
# controller (writing quickly, code may not be totally right, hopefully you get gist
data = Hash.new
data["items"] = []
@order.items.each do |item|
item_hash = {
"name" => item.name,
"amount" => Amount.where(item_id: item.id).first.amount,
"refund" => Refund.where(item_id:item.id).first.amount
}
data["items"] << item_hash
end
# view code
<% data["items"].each do |item| %>
<td><%= item["name"] %></td> …Run Code Online (Sandbox Code Playgroud) 我有CodeIgniter3的问题:找不到404页面
文件:application/controllers/Welcome.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('Welcome_Page');
}
public function tutorial()
{
$this->load->view('Tutorial_Page');
}
public function manual()
{
$this->load->view('Manual_Page');
}
public function forum()
{
$this->load->view('Forum_Page');
}
public function register()
{
$this->load->view('Register_Page');
}
public function login()
{
$this->load->view('Login_Page');
}
}
Run Code Online (Sandbox Code Playgroud)
文件:application/config/autoload/php
$autoload['helper'] = array('url');
Run Code Online (Sandbox Code Playgroud)
文件:application/config/routes.php
$route['default_controller'] = 'welcome';
$route['translate_uri_dashes'] = FALSE;
Run Code Online (Sandbox Code Playgroud)
文件:application/config/config.php
$config['base_url'] = 'http://subdomain.domain.tld';
$config['index_page'] = '';
Run Code Online (Sandbox Code Playgroud)
文件:.htaccess
RewriteEngine On
RewriteCond …Run Code Online (Sandbox Code Playgroud) php model-view-controller .htaccess codeigniter codeigniter-3
我正在尝试创建一个动态表,其中表中的每一行都有一个"修改"按钮,弹出一个模式,其中有一个表单请求信息.
这是我目前的CSHTML代码:
<body>
<div id="container">
<h1>Fingerprint Tool</h1>
<form id="userIdForm" method="post">
Type in your UserId: <input name="userId" type="number" id="formUserId" />
<input type="submit" />
</form>
@if (Model != null)
{
<h2>List of Fingerprints for user</h2>
<div id="tableDiv">
<table class="fingerprintTable">
<thead>
<tr>
<th>User ID</th>
<th>Fingerprint ID</th>
<th>FingerprintGrant ID</th>
<th>PaymentType ID</th>
<th>Fingerprint</th>
<th>IsDeleted</th>
<th>Status ID</th>
<th>Created Date</th>
<th>Updated Date</th>
<th>Modify</th>
</tr>
</thead>
<tbody>
@foreach (var fingerprint in Model.Fingerprints)
{
<tr>
<td id="userId">@fingerprint.UserId</td>
<td id="fingerprintId">@fingerprint.FingerprintId</td>
<td id="fingerprintGrantId">@fingerprint.FingerprintGrantId</td>
<td id="paymentTypeId">@fingerprint.PaymentTypeId</td>
<td id="fingerprint">@fingerprint.Fingerprint</td>
<td id="isDeleted">@fingerprint.IsDeleted</td>
<td id="fingerprintStatusId">@fingerprint.FingerprintStatusId</td> …Run Code Online (Sandbox Code Playgroud)