Domanda

I have a table in my database and it has a column named title in nvarchar datatype. I want to save the title that user enters in a textbox to table. In my view I used

@using (Html.BeginForm("savetodb", "Advertise", FormMethod.Post, new { enctype = "multipart/form-data" })) { 
    @Html.TextBoxFor(m => m.AdTitle)
} 

This view is strongly typed view from a ViewModel that has this property

public string AdTitle { get; set; }

I know how to save data from controller to database but I don't know how can I access data in my controller(in savetodb() function). Can anybody help me please? Thanks

È stato utile?

Soluzione

public ActionResult SaveToDB(YourViewModel model)
{
    // Do what you want with AdTitle here.
    SaveInDB(model.AdTitle);
}

Altri suggerimenti

View Model coud be one way but in this case i think it`s better to use auto model binding of MVC 3.so if u define a string parameter with the name of AdTitle.

 public ActionResult SaveToDB(String AdTitle)
{
    // Do what you want with AdTitle here.
    SaveInDB(AdTitle);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top