我有一个HttpPost和HttpGet版本的动作方法Rate():
http://pastebin.com/embed_js.php?i=6x0kTdK0
public ActionResult Rate(User user, Classified classified)
{
var model = new RatingModel
{
CurrentUser = user,
RatedClassified = classified,
};
return View(model);
}
[HttpPost]
public ActionResult Rate(RatingModel model)
{
model.RatedClassified.AddRating(model.CurrentUser, model.Rating);
return RedirectToAction("List");
}
Run Code Online (Sandbox Code Playgroud)
HttpGet Rate()返回的视图:
@model WebUI.Models.RatingModel
@{
ViewBag.Title = "Rate";
}
Rate @Model.RatedClassified.Title
@using(Html.BeginForm("Rate","Classified", FormMethod.Post))
{
for (int i = 1; i < 6; i++)
{
Model.Rating = i;
<input type="submit" value="@i" model="@Model"></input>
}
}
Run Code Online (Sandbox Code Playgroud)
我试图找出通过Form发送模型到Post方法,我的想法是提交按钮的标签中的值"模型"将是这样做的参数,但是如果我是null则通过Post方法中的断点.for循环试图创建5个按钮来发送正确的评级.
谢谢
我有一个绘图程序,允许用户绘制线条,框,文本,甚至JPEG.
我希望能够保存用户绘制的图像,但是我对如何将用户的创建转换为我可以轻松使用的格式(Image或BufferedImage)感到有点困惑.
用户在JPanel上绘制他们的内容(让我们称之为JPanel inputPanel).如果用户单击一个按钮(让我们调用此按钮saveButton).弹出一个JFileChooser,询问将其保存到哪里,然后BAM,保存创建(我知道如何以编程方式保存图像).
有没有一种简单的方法可以以这种方式将JPanel转换或转换为Image或BufferedImage?
谷歌搜索/搜索StackOverFlow仅提供使用setIcon()将图像绘制到JPanel的解决方案,这没有帮助.