none
asp.net mvc form dan veri alma RRS feed

  • Soru

  • @if (Model.IsGiftCard)
    {
        using (Html.BeginForm("AddToCartProduct", "ShoppingCart", FormMethod.Post))
        {
        <div class="giftCard">
            @T("Products.GiftCard.Field.Fill")

            <dl>
                <dt>@Html.LabelFor(model => model.RecipientName):</dt>
                <dd>
                    @Html.TextBoxFor(model => model.RecipientName)
                </dd>
                @if (Model.GiftCardType == Nop.Core.Domain.Catalog.GiftCardType.Virtual)
                {
                <dt>@Html.LabelFor(model => model.RecipientEmail): </dt>
                <dd>
                    @Html.TextBoxFor(model => model.RecipientEmail)
                </dd>
                }

    şeklinde devam eden form sayfam var ve bu formu post ettigimde 

    [HttpPost]
            [ValidateInput(false)]
            public JsonResult AddToCartProduct(AddToCartModel model, FormCollection form)
            {

     metodunda yakalıyorum ancak form verilerinin hiçbiri gelmiyor. ancak breakpoint koyunca bu metoda düşüyo. Neden form verileri gelmez ki . Fikriniz var mı ?

             
    4 Aralık 2013 Çarşamba 10:33

Yanıtlar

  • ilk yükleme örneği
    public ActionResult Page()
    {
        AddToCartModel model = new AddToCartModel();
        model.IsGiftCard = true;
        return View(model);
    }


    .cshtml

    @model AddToCartModel @if (Model.IsGiftCard) { using (Ajax.BeginForm("AddToCartProduct", "ShoppingCart", null, new AjaxOptions { HttpMethod = "POST", OnSuccess = "SUCCESS" }, new {name = "mainForm", id = "mainForm"})) { <div class="giftCard"> @T("Products.GiftCard.Field.Fill") <dl> <dt>@Html.LabelFor(model => model.RecipientName):</dt> <dd> @Html.TextBoxFor(model => model.RecipientName) </dd> @if (Model.GiftCardType == Nop.Core.Domain.Catalog.GiftCardType.Virtual) { <dt>@Html.LabelFor(model => model.RecipientEmail): </dt> <dd> @Html.TextBoxFor(model => model.RecipientEmail) </dd> }


    AddToCartProduct methodu
    [HttpPost]
    public JsonResult AddToCartProduct(AddToCartModel model)
    { 
         if (!ModelState.IsValid)
         {
              return Json(new { Status = false, ErrorMessage = "Hata Mesajı") }, "text/plain");
         }
    
         string RecipientName = model.RecipientName;
    
         //..................
    }



    7 Aralık 2013 Cumartesi 17:37

Tüm Yanıtlar

  • Selam,

    .cshtml sayfasının başına

    @model AddToCartModel

    eklemiş olman lazım.


    http://www.tiravoglu.com

    4 Aralık 2013 Çarşamba 18:56
  • ilk yükleme örneği
    public ActionResult Page()
    {
        AddToCartModel model = new AddToCartModel();
        model.IsGiftCard = true;
        return View(model);
    }


    .cshtml

    @model AddToCartModel @if (Model.IsGiftCard) { using (Ajax.BeginForm("AddToCartProduct", "ShoppingCart", null, new AjaxOptions { HttpMethod = "POST", OnSuccess = "SUCCESS" }, new {name = "mainForm", id = "mainForm"})) { <div class="giftCard"> @T("Products.GiftCard.Field.Fill") <dl> <dt>@Html.LabelFor(model => model.RecipientName):</dt> <dd> @Html.TextBoxFor(model => model.RecipientName) </dd> @if (Model.GiftCardType == Nop.Core.Domain.Catalog.GiftCardType.Virtual) { <dt>@Html.LabelFor(model => model.RecipientEmail): </dt> <dd> @Html.TextBoxFor(model => model.RecipientEmail) </dd> }


    AddToCartProduct methodu
    [HttpPost]
    public JsonResult AddToCartProduct(AddToCartModel model)
    { 
         if (!ModelState.IsValid)
         {
              return Json(new { Status = false, ErrorMessage = "Hata Mesajı") }, "text/plain");
         }
    
         string RecipientName = model.RecipientName;
    
         //..................
    }



    7 Aralık 2013 Cumartesi 17:37