2012-06-05 2 views
0

업로드 한 Excel 파일의 행 양에 따라 동적으로 생성하는 폼이 있습니다. 설명 문자열을 살펴보고 동적으로 생성 된 드롭 다운 목록을 설명의 텍스트를 기반으로 지정된 값으로 설정하는 논리는 어디에서 추가 할 수 있습니까? "blabla"가 설명 문자열에있는 경우 드롭 다운 목록 값을 4로 설정하십시오.ASP.NET MVC 3 동적으로 생성 된 드롭 다운 컨트롤의 로직

자바 스크립트에서이 작업을 수행해야합니까? 그게 내게 깨끗하다고 ​​느끼지 않기 때문이지. 내 비즈니스 로직을 내 컨트롤러에서 처리하는 것을 선호하지만이 디자인에서 어떻게 작동하는지 확신 할 수 없습니다.

미리보기 기본적으로 그냥 거래라는 이름의 내 편집기 템플릿에 대한 링크 페이지 :이 편집기 템플릿 거래에서

@using (Html.BeginForm("Preview", "Import", FormMethod.Post)) 
{ 
    <table border="1" style="border-color: #FFFFFF"> 
    @Html.EditorFor(m => m.Transactions, new { Categories = Model.Categories }) 
    </table> 
    <input id="btnSave" type="submit" value="Opslaan in database" /> 
} 

, 나는 약간의 정적 데이터를 표시하고 텍스트 상자

내 코드는 다음과 같습니다

<tr> 
    <td style="width: 40px; padding: 5px; background-color: @CurrencyHelper.GetCurrencyColor(Model.Amount)" align="right" nowrap="nowrap">@Html.Raw(CurrencyHelper.GetCurrency(Model.Currency, Model.Amount)) 
    </td> 
    <td style="white-space: nowrap; padding: 5px;">@Model.DateTime.ToString("dd-MM-yyyy") 
    </td> 
    <td style="padding: 5px;">@Model.Description 
    </td> 
    <td style="padding: 5px;">@Html.EditorFor(m => m.ShortDescription) 
    </td> 
    <td style="padding: 5px;">@Html.DropDownListFor(m => m.CategoryId, new SelectList(ViewData["Categories"] as IEnumerable<Category>, "CategoryId", "Name")) 
    </td> 
</tr> 

내 컨트롤러, 뷰 모델의 데이터를 입력 : 내가 이전에 다른 페이지에 업로드 한 Excel에서 각 행에 대해 드롭 다운리스트 :

//Attach unique Transactions and Categories to ViewModel 
var viewModel = new ImportViewModel() 
{ 
    Transactions = uniqueTransactions.ToList(), 
    Categories = categoryRepository.GetCategories().OrderBy(c => c.Name).ToList() 
}; 

답변

0

정적

public class HomeController : Controller 
    { 
     public ActionResult Index() 
     { 
      private MovieDBContext db = new MovieDBContext(); 
      var GenreLst = new List(); 
      var GenreQry = from d in db.Movies 
          orderby d.Genre 
          select d.Genre; 
      GenreLst.AddRange(GenreQry.Distinct()); 
      ViewBag.Courses = new SelectList(GenreLst); 
      return View(); 
     } 
    } 
@{ 
    ViewBag.Title = "Home Page"; 
} 
Index 

@using(@Html.BeginForm("Index","Home",FormMethod.Get)) { 

Courses List; @Html.DropDownList("Courses") 
} 

public class HomeController : Controller 
    { 
     public ActionResult Index() 
     { 
      ViewBag.Message = "Welcome to the Training Courses..."; 
      List objcourses = new List(); 
      objcourses.Add("Asp.Net"); 
      objcourses.Add("MVC"); 
      objcourses.Add("WCF"); 
      objcourses.Add("WPF"); 
      objcourses.Add("C#.Net"); 
      ViewBag.Courses = new SelectList(objcourses); 
      return View(); 
     } 
    } 

@{ 
ViewBag.Title = "Home Page"; 
} 
Index 
@using(@Html.BeginForm(“Index”,”Home”,FormMethod.Get)) { 
Courses List; @Html.DropDownList(“Courses“) 
} 

동적 결합 제본

관련 문제