Click here to Skip to main content
15,883,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
when i click submit button in my actionresult get invoked but parameters are all empty in model which is models.Soru named as form.

it sends all properties like in my Soru() constructer. Empty string or 0 if int. textboxfor<> cant post values even i edit textbox values on view. I started a new project to try it and with a simple class and view i submit form and when i debug i get into httpPost methot but just nothing in posted class. i can get form with formcollection but i want regular mvc way. 

public ActionResult Index(Models.Soru form) on this line i want form to have class properties with edited textboxfor values but it gets nothing.

does anyone have idea?




C#
public class Soru
{
    public int ID;
    public string Ad;
    public string SoruIcerik;
    public string Cevap;
    public int Sira;

    public Soru()
    {
        ID = 0;
        Ad = string.Empty;
        SoruIcerik = string.Empty;
        Cevap = string.Empty;
        Sira = 0;
    }
}


//here is controller

C#
[ValidateInput(false)]
[HttpPost]
public ActionResult Index(Models.Soru form)
{

    return null;
}

// and view

C#
@model x.Models.Soru
@{


using (Html.BeginForm())
{
    <div class="col-md-7">

        @Html.TextAreaFor(m => m.SoruIcerik, new { @name = "soruIcerik", @id = "soruIcerik", @rows = "10", @cols = "80" })

    </div>
    <div class="col-md-5">
        <div class="col-md-4 formSatiri">
            <label class="formSatiri">
                Soru Adi :
            </label>
        </div>
        <div class="col-md-8">
            @Html.TextBoxFor(m=>m.Ad, new { @class = "formSatiri" })
        </div>
        <div class="col-md-4 formSatiri">
            <label class="formSatiri">
                Cevap :
            </label>
        </div>
        <div class="col-md-8">
            @Html.TextBoxFor(m => m.Cevap, new { @class = "formSatiri" })
            </div>
        <div class="col-md-12 formSatiri">
            <input type="submit" class="btn btn-primary btn-sm pull-left" value="Kaydet"/>
        </div>
    </div>
}

}
Posted
Updated 2-Aug-14 10:20am
v2

In some way i've learned my class variables should be like property.

C#
public int point {get; set;}


when i did this it is solved. but i am sure in my last SOA project i was using classes like up there and it was working. So it is little bit senseless in my head still.

Thank you anyway.
 
Share this answer
 
Comments
[no name] 21-Jul-14 3:15am    
yeah!!. get;set; properties are required in MVC to perform the DB operations and also to bind the values to the viewmodel from the view page that is strongly typed.
You can try with providing the action into the @using form itself.
@using("Action","Controller",...)

else,
in the Java Script file,
make an ajax call on click of the button. To the input type, give an id "submitForm" suppose 7 give the @using,html.BeginForm an id "formToBeSubmitted" suppose.
Then in the JS,
$("#submitForm").live('click',function(){
$.ajax({
type:"POST",
url:"controller/action",
data: $("#formToBeSubmitted").serialize. //this will post all the data to the viewmodel passed
as parameter in your post method.
success:function(){
//...//
}

});

})

hope this helps you..
 
Share this answer
 
Comments
hocka10 21-Jul-14 2:49am    
Yea i know posting via ajax or formcollection. they are working. but with this mvc way it is not working. i can get in the controller with submit button but with empty values. so it is not about using.
Here the model should be if you really want in MVC style
public class Soru
{
    public int ID{get;set;}
    public string Ad{get;set;}
    public string SoruIcerik{get;set;}
    public string Cevap{get;set;}
    public int Sira{get;set;}
   
}


And the view should have the @using form action and controller name defined
@model Matogram.Models.Soru
@{
 

using (Html.BeginForm("Index", "ControllerName", FormMethod.Post, null))
{
    <div class="col-md-7">
 
        @Html.TextAreaFor(m => m.SoruIcerik, new { @name = "soruIcerik", @id = "soruIcerik", @rows = "10", @cols = "80" })
 
    </div>
    <div class="col-md-5">
        <div class="col-md-4 formSatiri">
            <label class="formSatiri">
                Soru Adi :
            </label>
        </div>
        <div class="col-md-8">
            @Html.TextBoxFor(m=>m.Ad, new { @class = "formSatiri" })
        </div>
        <div class="col-md-4 formSatiri">
            <label class="formSatiri">
                Cevap :
            </label>
        </div>
        <div class="col-md-8">
            @Html.TextBoxFor(m => m.Cevap, new { @class = "formSatiri" })
            </div>
        <div class="col-md-12 formSatiri">
            <input type="submit" class="btn btn-primary btn-sm pull-left" value="Kaydet"/>
        </div>
    </div>
}
 
}


Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900