我想从MVC2控制器返回一个ActionResult图像.此图像是1x1白色像素(用于跟踪应用程序).我不想在磁盘或数据库中引用图像.我想在我的方法中生成图像,然后从控制器操作返回它.
任何人都知道如何生成1x1白色图像,可以传递到FileStreamResult以从控制器操作返回?
在AccountController中,在方法的最后我有:
RedirectToAction("EveryView", "Account");
Run Code Online (Sandbox Code Playgroud)
在同一个控制器文件中我有这个方法:
public ActionResult EveryView()
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
但这种方法永远不会被调用.我在'{'上有一个断点,它永远不会被击中!
我是extjs的新手,我正在使用MVC架构.
当我的应用程序引用控制器的方法时,我这样做(in MyApp.Application):
Mb.app.getController('Main').myMethod();
Run Code Online (Sandbox Code Playgroud)
它已经很久了,但我认为这是可行的方法.
当一个控制器在一个闭包中调用它自己的方法时,我被引导使用这个代码(在MyApp.controller.Main:
controllerMethodOne: function(){
Ext.Ajax.request({
url: ...,
params: ...,
success: (function(response){
list = Ext.JSON.decode(response.responseText);
list.forEach(function(item){
storeMenu.add(
Ext.create('Ext.menu.Item', {
text: item.text,
handler: function(el){MyApp.app.getController('Main').controllerMethodTwo()}
})
)
})
})
})
},
Run Code Online (Sandbox Code Playgroud)
我引用了方法,MyApp.app.getController('Main').controllerMethodTwo()因为this没有引用闭包中的控制器对象,因此this..controllerMethodTwo()不起作用.
我发现这完全令人费解,我希望有人有想法解决这个MyApp.app.getController问题.
感谢所有的建议,我可以优化我的代码并提出:
// in my controller
mixins: ['Mb.controller.mixin.StoreMenu'],
// I use that style of menus in two controllers thats why I use a mixin
init: function() {
this.control({
'#vg_storeMenu menuitem': {
click: this.onStoreMenuClicked
}
}) …Run Code Online (Sandbox Code Playgroud) 当我使用Spring MVC控制器并通过设置值来提交表单时,modelAttribute我丢失了一些未映射到表单中的模型字段.在此示例中,因为我没有映射年龄和地址,所以这些用户的字段会丢失,因此它们具有null价值.我不想让用户更改他们的年龄和地址,这就是为什么这些字段不在表单中.
方法控制器发布用户编辑表单:
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public String editionUser(Model model, @ModelAttribute("accountForm") User user,
BindingResult bresult,
RedirectAttributes redirectAttributes) {
//user.getAge() and user.getAddress are null
//Save the information...
}
Run Code Online (Sandbox Code Playgroud)
获取编辑用户页面的方法控制器:
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String initEdit(Model model) {
// the user fields are all filled
User user = userService.getUserById(...);
model.addAttribute("accountForm", user);
return "edition";
}
class User {
Long id;
String email;
String age;
String address;
String nickname;
// ...
}
Run Code Online (Sandbox Code Playgroud)
edition.jsp
<form:form …Run Code Online (Sandbox Code Playgroud) 过去几天非常令人沮丧.
我有一个安装了Devise的rails应用程序,我生成了一个新的User模型,我也生成了Devise视图.
当我在填写电子邮件和密码字段后单击"登录"时尝试以现有用户身份登录时会发生这种情况:
AbstractController::ActionNotFound - Could not find devise mapping for path "/sessions/user".
This may happen for two reasons:
1) You forgot to wrap your route inside the scope block. For example:
devise_scope :user do
get "/some/route" => "some_devise_controller"
end
2) You are testing a Devise controller bypassing the router.
If so, you can explicitly tell Devise which mapping to use:
@request.env["devise.mapping"] = Devise.mappings[:user]
:
devise (3.2.4) app/controllers/devise_controller.rb:84:in `unknown_action!'
devise (3.2.4) app/controllers/devise_controller.rb:59:in `assert_is_devise_resource!'
devise (3.2.4) app/controllers/devise_controller.rb:97:in `require_no_authentication'
activesupport (4.0.4) lib/active_support/callbacks.rb:397:in …Run Code Online (Sandbox Code Playgroud) 嗨我正在网上开发所以我有一个ajax函数调用一个控制器函数调用DAO函数(在DB上进行更改).我在控制器功能中得到了上面的例外..
控制器功能:
@RequestMapping(value="/changeIsPublic", method=RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody boolean changeIsPublic(HttpServletRequest request, Locale locale, Model model, long transactionId, boolean isPublic) {
boolean result = false;
try {
boxDao.changeIsPublicStatus(transactionId, isPublic);
result = true;
} catch (Exception e) {
logger.debug("Failed to publish transaction. transaction ID: " + transactionId + e.getMessage());
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
DAO功能:
public Box changeIsPublicStatus(long id, boolean isPublic) {
Criteria criteria = getCurrentSession().createCriteria(Box.class);
criteria.add(Restrictions.eq("id", id));
Box transaction = (Box) criteria.uniqueResult();
transaction.setIsPublic(isPublic);
return transaction;
}
Run Code Online (Sandbox Code Playgroud)
例外:
SEVERE: Servlet.service() for servlet …Run Code Online (Sandbox Code Playgroud) 如何在 ASP.NET Core (5.0) 中传递可选(可为空)[FromBody] 参数?如果我不在请求中发送正文,则会收到 415 不支持的媒体类型错误。可以配置吗?如果可以,如何在控制器或操作而不是应用程序级别上进行配置?我认为它必须与模型验证有关,但不确定。谢谢。
[HttpGet("[action]")]
public async Task<IActionResult> GetElementsAsync([FromBody] IEnumerable<int> elements = default)
{
var result = await dataService.GetData(elements);
return Ok(result);
}
Run Code Online (Sandbox Code Playgroud)
编辑:澄清一下:
在某些MVC框架中,如果您希望执行某些代码并呈现某些部分视图,则可以从视图中调用控制器操作.我不确定在Spring MVC中执行它的正确方法是什么
我想要一组JSP模板.其中一些将是页面布局,其中一些将是小组件,如分页器,登录框,菜单,标签云等等.这些组件中的每一个都需要一些bean或控制器操作来将一些数据设置到ViewAndModel中,以便视图可以使用它.
问题是我不想在每次调用中设置所有这些对象.我的注册管理员只关心注册处理.所以现在我该怎么做呢?如何从视图中调用DI bean或控制器以准备部分视图?或者我应该创建一些映射?或者我是从完全错误的角度来解决问题的?
我试图理解Ext JS 4(MVC)如何处理按钮,组合框和类似的工作.
具体来说,我相信MVC我们应该在控制器init函数中使用"this.control".
例如,我有以下工作:
this.control({
'eventlist': {
itemdblclick: this.eventRowClicked
},
'eventedit button[action=save]': {
click: this.updateEvent
}
});
Run Code Online (Sandbox Code Playgroud)
看起来很简单,我选择'eventlist'视图并为网格注册eventRowClicked事件.然后,在我的'eventedit'视图中,捕获按钮单击(保存按钮).
我接下来需要的是响应组合框选择或更改事件.我认为我有多个组合框,所以我需要一个特定的组合框.
我尝试了这个,但它没有用(我也试过选择而不是改变):
'eventedit dispositionpop': {
change: function(combo, ewVal, oldVal) {
debugger;
}
}
Run Code Online (Sandbox Code Playgroud)
我能找到的所有例子都不使用'this.control',他们要么将组件(Ext.get?)抓取到变量中,要么类似.我相信那些方法不是合适的mvc - 或者可能不是Ext JS 4最有效的方法.
所以我想知道两件事 - 我将如何注册特定的组合框选择或更改事件,以及我可以阅读什么来更好地了解this.control中发生的事情 - 例如,那些css选择器?
我试图将HTML返回到我的Spring MVC控制器时遇到了一个问题.
它看起来像这样:
@RequestMapping(value = QUESTION_GROUP_CREATE_URL, method = RequestMethod.POST)
public
@ResponseBody
String createQuestionGroup(@RequestBody JsonQuestionGroup questionGroup, HttpServletResponse response) {
// questionGroup - this comes OK.
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
return "<div></div>";
}
Run Code Online (Sandbox Code Playgroud)
我的Spring配置:
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false"/>
<property name="favorParameter" value="true"/>
<property name="mediaTypes">
<value>
json=application/json
xml=application/xml
html=application/html
</value>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我看到firebug响应就像:{"String":"<div></div>"}我怎么能告诉这个方法发送简单的HTML作为响应?
controller ×10
asp.net-mvc ×2
c# ×2
extjs ×2
java ×2
spring ×2
spring-mvc ×2
view ×2
asp.net-core ×1
closures ×1
dao ×1
devise ×1
events ×1
exception ×1
extjs4 ×1
extjs4.2 ×1
forms ×1
image ×1
java-ee ×1
jsp ×1
ruby ×1
session ×1
spring-form ×1
templates ×1