[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateUser([Bind(Exclude = "Id")] User user)
{
...
db.SubmitChanges();
ViewData["info"] = "The account has been created.";
return RedirectToAction("Index", "Admin");
}
Run Code Online (Sandbox Code Playgroud)
这不会在redirectToAction之后的viewdata中保留"info"文本.我将如何以最优雅的方式解决这个问题?
我目前的想法是将Index controlleraction中的东西放在[NonAction]中并从Index操作和CreateUser操作中调用该方法,但我觉得必须有更好的方法.
谢谢.
我正在尝试为使用AJAX GET请求访问的JSON响应设置content-type标头.我已经关注了博客和面包店的教程,但我总是从CakePHP收到'text/html'.如何正确设置内容类型标题?
这是我目前的代码:
public function admin_controller_actions_ajax()
{
Configure::write('debug', 0);
if ($this->RequestHandler->isGet()) {
$this->autoRender = FALSE;
$aco_id = $this->params['url']['aco_id'];
$aro_id = $this->params['url']['aro_id'];
assert('$aco_id != NULL && $aro_id != NULL &&
is_numeric($aco_id) && is_numeric($aro_id)');
$actions = $this->Resource->getActionsForController($aco_id, $aro_id);
assert('is_array($actions) && is_array($actions[0])');
/* I made RequestHandler part of the $components property */
$this->RequestHandler->setContent('json');
$this->RequestHandler->respondAs('json'); /* I've tried 'json', 'JSON', 'application/json' but none of them work */
$this->set('json_content', json_encode(array('response' => $actions[0])));
$this->layout = NULL;
$this->render('/json/default');
}
}
/* json/default.ctp */
<?php echo $json_content; ?> …Run Code Online (Sandbox Code Playgroud) 我有一个String,它包含一个文件的路径.我希望用户能够使用文件选择器选择路径和文件名,并让程序将String变量中给出的文件保存到他们选择的位置.做这个的最好方式是什么?
我正在使用原生iPhone应用程序.我能够将本地文件index.html 加载到UIWebView中:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];
Run Code Online (Sandbox Code Playgroud)
网络加载很好.现在,我想用一些参数加载web,就像在浏览器中输入一样:URL?var1 = myValue&var2 = myValue2
所以我可以在html文件的javascript中获取这些值.有没有办法将参数发送到本地html文件?
谢谢!
Crystal Reports中的常见做法是在执行某些背景逻辑的报表上使用公式.但为了防止它显示,你必须隐藏该字段.问题是,几年后,当你忘记它在哪里时,你怎么再找到它?我有一个名为@AddressedCount的公式的引用,但我找不到它在报告中的位置!
Keil与GCC的ARM7开发相比如何?我正在为一个中等规模的项目选择hw顾问,有些人使用keil,有些人使用gcc.我想知道参与任何一个选项的陷阱......
在html中,您可以使用例如文件(例如脚本或样式表).有没有办法做'如果没有',所以我可以包括除了一个以外的所有浏览器的文件?
我正在开发一个Web应用程序,允许用户在目录中键入项目的简短描述.我在我的textareas中允许Markdown,因此用户可以进行一些HTML格式化.
我的文本清理功能会在将任何输入的文本插入数据库之前将其删除:
public function sanitizeText($string, $allowedTags = "") {
$string = strip_tags($string, $allowedTags);
if(get_magic_quotes_gpc()) {
return mysql_real_escape_string(stripslashes($string));
} else {
return mysql_real_escape_string($string);
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,我存储在数据库中的所有内容都是Markdown - 没有其他HTML,甚至"基本HTML"(如此处的SO)是允许的.
允许降价会出现任何安全威胁吗?降价可以是XSSed,即使它没有标签吗?
我需要所有搜索关键字(术语)的列表,即在lucene索引中索引.我用谷歌搜索了它.但是,我没有得到解决方案.是否有可能获得所有搜索词的列表?