ورود

View Full Version : سوال: چرا مقدار dropdownlist بهاکشن فرستاده نمیشه؟



پروگرامنویس
شنبه 07 مرداد 1396, 19:25 عصر
درود
توی فرمی که ساختم مقدارهای txtEml و txtar در دیتابیس به درستی ذخیره میشن اما مقدار انتخابی دراپ داون لیست lst_tll ذخیره نمیشه.وقتی تو اکشن برک میزارم چیزی توی lst_tll پاس داده نشده و خالیه.
یه چیز دیگه اینکه چرا شرطم زمانی که فیلد خالی اجرا نمیشه؟
سپاس
متد اکشن


public ActionResult TellUs(string lst_tll,string txtEml,string txtar)
{
if (lst_tll == "" || txtEml == "" || txtar == "")
{
ViewBag.err = "Error";
}
else
{
Message msg = new Message();
msg.Subject = lst_tll;
msg.Email = txtEml;
msg.Body = txtar;
db.Messages.Add(msg);
db.SaveChanges();
db.Dispose();
db = null;
}
return View();
}


ویو فرم


@using (Html.BeginForm("TellUs", "Home",
FormMethod.Post, new { @class = "form-horizontal box_new_cmnt" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="row">
<div class="col-md-12 lbl_frm">
@Html.LabelFor(m => m.Subject)
</div>
</div>
<div class="row r_cmnt">
<div class="col-md-12 inpt_frm">
@Html.DropDownList("lst_tell",
new List<SelectListItem>
{
new SelectListItem() {Text="سفارش پروژه",Value="prj"},
new SelectListItem() {Text="درخواست درج آگهی",Value="agh"},
new SelectListItem() {Text="دیگر ...",Value="otr"}
}
, "انتخاب", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Subject, "", new { @class = "text-danger" })
</div>
</div>
<div class="row r_cmnt">
<div class="col-md-12 lbl_frm">
@Html.LabelFor(m => m.Email)
</div>
</div>
<div class="row r_cmnt">
<div class="col-md-12 inpt_frm">
@Html.TextBox("txtEml", "...", new { id = "eml" })
</div>
</div>
<div class="row r_cmnt">
<div class="col-md-12 lbl_frm">
@Html.LabelFor(m => m.FileUploud)
</div>
</div>
<div class="row r_cmnt">
<div class="col-md-12 inpt_frm">
@Html.TextBox("fle", null, new { type = "file", id = "up_tell" })
</div>
</div>
<div class="row r_cmnt">
<div class="col-md-12 lbl_frm">
@Html.LabelFor(m => m.Body)
</div>
</div>
<div class="row r_cmnt">
<div class="col-md-12 inpt_frm">
@Html.TextArea("txtar", new { rows = "6" })
</div>
</div>

<div class="row r_cmnt">
<div class="col-md-12 btn_frm">
<button type="submit">درج پیام</button>
</div>
</div>
}

RIG000
شنبه 07 مرداد 1396, 22:32 عصر
اکشن از نوع پست هست؟

نمونه =>





@using(Html.BeginForm("YourAction")){
@Html.DropDownList("EmpQuantity","--Select--", new { onchange = "this.form.onsubmit()" })%>


<input type = 'submit' value='Submit your Form' />
}


[HttpPost]
public ActionResult YourAction(string EmpQuantity)
{
//Get your DropDownValue through EmpQuantity
var selected = EmpQuantity;


//or access it through the Request.Form collection
var selected = Request.Form["EmpQuantity"];
}

پروگرامنویس
یک شنبه 08 مرداد 1396, 15:04 عصر
بله
بالای اکشن از HttpPost استفاده کردم