Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

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

share|improve this question

2 Answers 2

up vote 3 down vote accepted
public ActionResult SaveToDB(YourViewModel model)
{
    // Do what you want with AdTitle here.
    SaveInDB(model.AdTitle);
}
share|improve this answer

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);
}
share|improve this answer
3  
ummm... That code looks familiar. Where did I see it before...? I'm sure I did see it but where? – gdoron Jun 10 '12 at 9:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.