我进行了很多搜索,以在DropDownList中获取选定的值以使用MVC 4将其发送到控制器,但我发现了类似的内容:Request.Form [“ id”],但它们不满足我的需求。
我有这个表格:
<div class="editor-label">
@Html.LabelFor(model => model.IDTYPE, "TYPES")
</div>
<div class="editor-field">
@Html.DropDownList("IDTYPE", String.Empty)
@Html.ValidationMessageFor(model => model.IDTYPE)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.IDFLIGHT, "FLIGHTS")
</div>
<div class="editor-field">
@Html.DropDownList("IDFLIGHT", String.Empty)
@Html.ValidationMessageFor(model => model.IDFLIGHT)
@Html.ActionLink("Add New flight","Create","Flight",null,new{@style="font-size:16px;", @class="popup"})
</div>
我不想使用表单中的Post方法将数据发送到控制器,而是使用以下脚本,该脚本用于名为Aurigma的插件,该插件用于上传图像并在Controller中调用操作。
这是代码:
<script type="text/javascript">
var uploader = $au.imageUploaderFlash({
id: 'Uploader1',
licenseKey: '77FF4-00485-962F7-E117E-11414-86DBBB',
folderProcessingMode: 'Upload',
restrictions: { fileMask: '*.jpg;*.jpeg;*.png;*.gif;*.bmp' },
messages: { fileNameNotAllowed: 'You can add only images.' },
width: '100%',
height: '400px',
converters: [
{ mode: '*.*=SourceFile' }
],
uploadSettings: {
actionUrl: '@Url.Action("Ajouter", "Image")'
}
});
uploader.writeHtml();
因此,我想在两个DropDownLists IDFLIGHT和IDTYPE中获取所选值的ID,并将其传递到actionURL中。所以,我想做这样的事情:
actionUrl: '@Url.Action("Ajouter", "Image", new { IdFlight = "id for flight", IdType = "id for type"})'
这是我的控制器:
[HttpPost]
public ActionResult Ajouter(int idflight, int idtype)
{
for (int i = 0;
i < Convert.ToInt32(Request.Form["PackageFileCount"]);
i++)
{
if (Request.Form["File0Mode_" + i] != "sourceFile")
throw
new Exception("Uploader expects to send original files.");
HttpPostedFileBase sourceFile;
sourceFile = Request.Files["File0_" + i];
Char[] sepDCap = { '_', '.' };
String[] data = sourceFile.FileName.Split(sepDCap);
string Jour = data[1];
string Mois = data[2];
string Annee = data[3];
string dateCreat = DateTime.Now.ToString();
Char[] sepTDate = { '-', '/',' ' };
String[] dateCr = dateCreat.Split(sepTDate);
string Jourdc = dateCr[0];
string Moisdc = dateCr[1];
string Anneedc = dateCr[2];
string pathToCreate = "~/Uploads/" + Anneedc + "/" + Moisdc + "/" + Jourdc;
if (!Directory.Exists(Server.MapPath(pathToCreate)))
{
Directory.CreateDirectory(Server.MapPath(pathToCreate));
}
string dir = Server.MapPath(pathToCreate);
sourceFile.SaveAs(dir + "/" + sourceFile.FileName);
DateTime dateCapt = Convert.ToDateTime(Jour + "-" + Mois + "-" + Annee);
double latitude = Convert.ToDouble(data[4]);
double altitude = Convert.ToDouble(data[5]);
string pathImage = pathToCreate;
double longitude = Convert.ToDouble(data[6]);
IMAGES img=new IMAGES();
img.IDFLIGHT = idflight;
img.IDTYPE = idtype;
img.DATECAPTURE = dateCapt;
img.LATITUDE = latitude;
img.ALTITUDE = altitude;
img.PATHIMAGE = pathImage;
img.CREATED = Convert.ToDateTime(dateCreat);
img.LONGITUDE = longitude;
ImageService imgSce = new ImageService();
imgSce.create(img);
}
Response.Write("Upload Complete");
return null;
}
谢谢 !
参考方案
@Url.Action()
是剃刀代码,在将其传递给视图之前已在服务器上进行了解析。要根据下拉列表中的选定值构建url,请使用
actionUrl: '@Url.Action("Ajouter", "Image")' + '?idflight=' + $('#IDFLIGHT').val() + '&idtype=' + $('#IDTYPE').val()
在线测试系统ASP.NET MVC - javascript我能够按ID显示问题,但不知道如何为不同用户随机显示问题,并且每次用户登录新的随机组合时都会显示问题。有人可以指导吗?我的控制器:public ActionResult Index() { var question = Quiz.Instance.LoadQuiz(); return View(question); } [HttpPost] public A…
调试捆绑和版本化的javascript文件 - javascript我已经使用Bundleconfig.cs将我的JavaScript文件打包如下:bundles.Add(new ScriptBundle("~/bundles/resultscripts").Include( "~/Scripts/spectrum.js", "~/Scripts/notify.js"…
从ASP.NET MVC中的AngularJS控制器加载数据而无需加载整个页面 - javascript这是我的动作: [HttpPost, ValidateAntiForgeryToken] public ActionResult GetData() { //get data from DB and populate model with data return View("Data", model); } 该视图是: @model UI…
我可以在ID为键而不是ASP.NET MVC(C#)中的数组的情况下输出JSON吗 - javascript因此,在ASP.NET MVC中,我有一个Controller动作,如下所示:public JsonResult People() { var people = db.People.ToList(); return Json(people); } 并在退出时将返回如下内容:[ { "ID": 1, "Name": …
.NET C#Webbrowser填充输入,不带ID或类名 - javascript我需要在网络浏览器中填写一个输入,但这不起作用。我认为必须使用name属性来完成,但是怎么做呢?foreach (HtmlElement login in webBrowser1.Document.GetElementsByTagName("input")) { if (login.GetAttribute("name"…