2013-11-26 22 views
-1

我是ASP.NET MVC 3和Razor的新手。我想在一個視圖中製作多種形式。所有形式(紅色矩形)將顯示取決於我在「Jenis Registrasi」下拉列表中選擇的內容(紅色箭頭)。有時很少的表單需要加載不同的模型。級聯下拉菜單改變視圖和模型ASP.NET和剃刀

這是怎麼實現的?

對不起,代表題目和問題。謝謝你指導我。 :D screenshot

+0

的可能重複[在MVC 3 Razor視圖中級聯下拉](http://stackoverflow.com/questions/4458970/cascading-drop-downs-in-mvc-3-razor-view) –

回答

0

我有點把它扔在一起,但它類似於我在很多ajax情況下做的事情。我肯定會列出一些邏輯。也許在JavaScript中添加blockUi。

在你的客戶,你將有類似

$('RegistrasiDropDown').change(function() { 
    $.get('@Url.Action("GetExtraFormFields")', { id: $('#RegistrasiDropDown').val() }, function (data)  { 
     if (data.success == false) { 
      //Handle Error 
      }); 
     } else { 
      $('#ExtraFormSection').html(data); 
     } 
    }) 
}); 

在你的控制器,你將有類似(在C#),但這個概念將在VB一樣

public ActionResult GetExtraFormFields(string id) 
    { 
     try 
     { 
      var registrationItem= GetRegistrationItemById(id); 
      if (condition1 == true) //Replace your own logic here. 
      { 
       var model = new ModelType1 { 
        Prop1 = "foo"; 
       } 
        return PartialView("_PartialView1", model) 
      } 
      else if()//// and so on 

     }     
     catch (Exception exception) 
     { 
      return return Json(new { success = false, message = exception.msg }, JsonRequestBehavior.AllowGet); 
     } 
    } 
+0

感謝您的答案,我會嘗試它第一 – andrefadila