2017-01-04 30 views
0

Im新的ASP .NET MVC Web Aplications和我請幫助。我需要summ兩個值(「Cena」和「Kolicina」)並保存到文本框「Znesek」中。我應該怎麼做?我想這(How to multiply values of two textboxes in Asp.net MVC),但它不是爲我工作:/在Asp.net MVC中總結兩個文本框的值

這裏是我的.cshtml文件:

<div class="form-group"> 
     @Html.LabelFor(model => model.kolicina, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
      @Html.EditorFor(model => model.kolicina, new { htmlAttributes = new { @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.kolicina, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     @Html.LabelFor(model => model.cena, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
      @Html.EditorFor(model => model.cena, new { htmlAttributes = new { @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.cena, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     @Html.LabelFor(model => model.znesek, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
      @Html.EditorFor(model => model.znesek, new { htmlAttributes = new { @class = "form-control" } }) 
      @Html.ValidationMessageFor(model => model.znesek, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

Acctual form

請幫助我,我需要改變或者我需要做一些行動?

編輯: 當然,我有@ Html.BeginForm和一切需要查看代碼,這只是部分代碼。一切工作,我都可以保存到SQL數據庫並顯示它,我剛下來知道

多個字段如何......這是我的CONTROLER郵編:

public ActionResult Create() 
    { 
     ViewBag.zapStDoumenta_tk = new SelectList(db.dokumentGlava, "zapStDokumenta", "zapStDokumenta"); 
     return View(); 
    } 

    [HttpPost] 
    [ValidateAntiForgeryToken] 
    public ActionResult Create([Bind(Include = "zapStPostavke,artikel,kolicina,cena,znesek,davek,popustNaPostavko,zapStDoumenta_tk")] postavkaDokumenta postavkaDokumenta) 
    { 
     if (ModelState.IsValid) 
     { 
      db.postavkaDokumenta.Add(postavkaDokumenta); 
      db.SaveChanges(); 
      return RedirectToAction("Index"); 
     } 

     ViewBag.zapStDoumenta_tk = new SelectList(db.dokumentGlava, "zapStDokumenta", "krajIzdaje", postavkaDokumenta.zapStDoumenta_tk); 
     return View(postavkaDokumenta); 
    } 
+3

顯示你的js代碼.. –

+0

有你有形式的標籤? (即'@ Html.BeginForm')。顯示完整的視圖代碼以及您要發送到的控制器方法。 – markpsmith

+0

我編輯了我原來的帖子。 – makaroN

回答

2

試試這個JavaScript代碼。這應該工作。

$(function(){ 
 

 
    $("#kolicina,#cena").keyup(function(e){ 
 

 
    var val1=$("#kolicina").val(), 
 
     val2=$("#cena").val(), 
 
     result=""; 
 

 
    if(val1.length > 0){ 
 
    result += val1; 
 
    } 
 

 
    if(val2.length > 0){ 
 
    result += val2; 
 
    } 
 

 
    $("#znesek").val(result); 
 

 
    }); 
 

 
});

+0

非常感謝你的工作就像一個魅力:) – makaroN

相關問題