我正在开发一个使用 J2EE 和 Spring Roo 作为框架的 Web 应用程序。
我想创建一个带有两个提交按钮的表单:
另一个用于保存和完成
<form action="mycontroller" method="post">
<input type="submit" value="Save and continue"/>
<input type="submit" value="Save and finish"/>
</form>
所以我可以选择将数据存储在数据库中并添加更多条目,或者存储数据并完成该过程。
如何检查在处理操作的控制器的方法中单击了什么提交按钮?
public class MyController {
void actionMethod(...) {
// check which submit was clicked
}
}
Run Code Online (Sandbox Code Playgroud) 现在我正在使用服务将数据从视图传递到其他视图(不同的控制器也是如此),在视图 A 中,我有控制器 CtrA,我用来传递数据的服务是:
.factory(
'editreportservices',
[
'$q',
'sessionId',
function($q, sessionId) {
var sharedata = {};
var org={};
function passed(data){
sharedata = data;
};
function getsharedata(){
return sharedata;
};
function passedorg(data) {
org=data;
}
function getorg() {
return org;
}
return{
passed:passed,
getsharedata:getsharedata,
passedorg:passedorg,
getorg:getorg
}
}]);
Run Code Online (Sandbox Code Playgroud)
在 CtrA 中,如果我按下按钮,我将为 editreportservices.passed(report) 设置值,例如:
$scope.goeditpage = function(report){if(report){
editreportservices.passed(report);
}
else{
report={}
editreportservices.passed(report);
};
$state.go('editreport');
}
Run Code Online (Sandbox Code Playgroud)
并且它也将更改为视图 B,并且在 VIew BI 中可以使用 $scope.lin = editreportservices.getsharedata() 访问数据,它按预期工作。但是有一个问题,我不确定它是否是一个错误,如果用户刷新页面,从 viewA 传递的数据将消失。这可能是一个糟糕的用户体验,无论如何II可以在从VIewA传递之后将数据保留在viewB中吗?
我正在使用剃刀语法。我有价值,例如 1123456 返回到我的观点。我想显示为$1,123,456 USD。
我有以下行
@Model.TotalCost
Run Code Online (Sandbox Code Playgroud)
如何在其上应用字符串格式以显示 1,123,456 美元等值?
所以我们在团队中增加了一名新程序员,他对如何在 MVC 中创建模型有一些想法,这与我们之前创建模型的方式不同。例如,我们有一个系统,用户可以在其中提交文件请求,并且该系统中有一个页面,用户可以在其中计算完成该文件请求的费用。此费用创建页面可以输入有关费用的一些数据以及相关发票。用户可以添加发票行项目并使用它们来自动计算费用总额。在这种情况下,我们通常会创建如下所示的模型。
public class Fee
{
public virtual Guid RequestID { get; set; }
public virtual Guid FeeID { get; set; }
public string FeeTitle { get; set; }
public decimal FeeAmount { get; set; }
public DateTime? DueDate { get; set; }
public decimal AmountPaid { get; set; }
public Invoice Invoice { get; set; }
public List<InvoiceLineItem> LineItems { get; set; }
}
public class Invoice
{
// Additional Invoice Data (To, From, etc)
}
public class …Run Code Online (Sandbox Code Playgroud) 我有一种方法是调用 api 方法。该 api 方法包含插入、更新、删除的 SQL 语句。但是当存储过程抛出任何错误时,如何在前面显示为错误消息。我正在使用 ASP .NET 5 和 MVC 6。我的方法如下:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Method(Model model)
{
string url = ConfigurationSettingHelper.BaseUrl + "apiurl";
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.PostAsJsonAsync<Model>(url, model);
if (response.IsSuccessStatusCode)
{
var data = await response.Content.ReadAsStringAsync();
var Msg = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(data);
if (!string.IsNullOrEmpty(Convert.ToString(Msg)))
{
//Here code to display error message.
}
}
}
return View();
}
Run Code Online (Sandbox Code Playgroud)
帮助我在页面上显示 Msg 变量字符串消息。
谢谢你
有人问我,假设我已经在 route.config 中为 URL 定义了路由,并且我已经在基于属性的路由中定义了相同的路由。那么在每种情况下谁的优先级更高。如果我们可以在 route.config 中实现相同的基于属性的路由有什么用。
我正在尝试按照本教程制作联系表单,但我一直遇到错误:uninitialized constant ApplicationMailer提交表单后。
跟踪提供以下信息:
app/mailers/message_mailer.rb:1:in <top (required)>'
app/controllers/messages_controller.rb:9:in create'
actionpack (4.2.5) lib/action_controller/metal/implicit_render.rb:4:in send_action'
actionpack (4.2.5) lib/abstract_controller/base.rb:198:in process_action'
actionpack (4.2.5) lib/action_controller/metal/rendering.rb:10:in process_action'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:20:in block in process_action'
activesupport (4.2.5) lib/active_support/callbacks.rb:117:in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:117:in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:555:in block (2 levels) in compile'
activesupport (4.2.5) lib/active_support/callbacks.rb:505:in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:505:in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:92:in __run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in _run_process_action_callbacks'`
Run Code Online (Sandbox Code Playgroud)
这是我的文件: controllers/messages_controller.rb
class MessagesController < ApplicationController
def new
@message = Message.new
end
def create
@message = Message.new(message_params) …Run Code Online (Sandbox Code Playgroud) 假设您将使用像Jira这样的问题和项目跟踪软件来规划下一个即将到来的项目。
您决定使用像Laravel这样的 PHP Web 框架来开发遵循模型-视图-控制器 (MVC) 架构模式的 Web 应用程序。
您将问题编写为用户故事,添加一些细节,等等。
[用户特定 - 组件]
- 作为用户,我希望能够管理用户。
- 作为用户,我希望能够注册一个新用户。
- 作为用户,我希望能够删除现有用户。
...
[消息特定 - 组件]
- 作为用户,我希望能够进行对话。
- 作为用户,我希望能够向用户发送消息。
- 作为用户,我希望能够接收来自用户的消息。
- 作为用户,我希望能够在消息中使用表情符号。
- 作为用户,我希望能够将文件附加到消息中。
...
[特定任务 - 组件]
- 作为用户,我希望能够拥有一个任务板。
- 作为用户,我希望能够添加新任务。
- 作为用户,我希望能够为用户分配任务。
- 作为用户,我希望能够将任务标记为已完成。
...
你懂了?!目前没有问题。有些故事甚至可以分解成更小的故事,然后再分解成一些任务,然后是一些子任务。
让我们更进一步:您使用像github这样的源代码协作平台,结合Fish-Eye并决定使用智能提交来转换问题。您的问题和提交结构良好且易于跟踪。(美丽的想法)
如果您遵循框架 laravel 中的指南,您将有不同的任务需要跟进:
必须完成此任务,甚至更多任务才能确认组件已完成。我所说的组件是指上面定义的,比如用户、消息、任务。他们都有一些共同点,你会一遍又一遍地重复。但是您仍然希望使用完成问题所需的源代码填充问题。
User.php (模型关系)
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* Get the message record associated with the user. …Run Code Online (Sandbox Code Playgroud) 假设我有一个包含 20 个字段的模型,并且在我的索引页中,我想列出存储在我的数据库中的所有模型。在索引页面,我没有列出模型的所有字段,我只列出了 3 个字段。
所以,我做了两个类:
class CompleteModel {
public int Id { get; set; }
public string Field01 { get; set; }
public string Field02 { get; set; }
public string Field03 { get; set; }
public string Field04 { get; set; }
public string Field05 { get; set; }
...
public string Field20 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在,在我的控制器中,我可以使用:
await _context.CompleteModel.ToListAsync();
Run Code Online (Sandbox Code Playgroud)
但我觉得这似乎不是正确的方法,因为我获取了所有字段并且只使用了 3 个字段。
所以,我做了这个代码:
class ViewModel {
public string Field02 { get; set; }
public string Field04 …Run Code Online (Sandbox Code Playgroud) 我有一个查询,我稍微修改了一下,使它成为一个通用的 Iqueryable。然而,现在所有依赖它的代码都更具体地抛出一个错误,说“IQueryable 不包含‘Where’的定义”
我该如何解决这个问题,以便我的 Iqueryable 可以有一个“where”语句
IQueryable query = _db
.BatchPayments
.Where(
bp => ValidBatchStatuesIds.Contains(bp.Batch.BatchStatusId)
&& (!OnlineBatchTypes.Contains(bp.Batch.BatchTypeId)
|| (OnlineBatchTypes.Contains(bp.Batch.BatchTypeId)))
)
.GroupBy(i => i.BatchId)
.Select(i => new
{
Amount = i.Sum(j => j.Amount)
});
if (model.AmountFrom.HasValue && model.AmountFrom.Value > 0)
{
query = query.Where(bp => bp.Amount >= model.AmountFrom); // This is the line it bugs out on that I need to work
hasInput = true;
}
Run Code Online (Sandbox Code Playgroud) c# ×4
asp.net-mvc ×3
asp.net-core ×2
agile ×1
angularjs ×1
forms ×1
jakarta-ee ×1
jira ×1
laravel ×1
linq ×1
php ×1
razor ×1
routing ×1
ruby ×1
spring ×1
spring-roo ×1