formcollection

MVC2: How can I read control values for an action link?

夙愿已清 提交于 2019-12-11 06:25:32
问题 I'm passing in some model information to an ActionLink, but I'd also like to provide the action with the values of some inputs on the page. For example, if I had something like this: <input Name="MyInput" /> <%: Html.ActionLink("MyAction", "MyController", Model.Value); I'd like the action to be aware of both Model.Value (which is passed in via parameter), and the value of MyInput. Normally I would use a FormCollection, but I can't in this instance since I'm not doing a submit. So how can I

Symfony2 - ReferencedColumnName id is null

拟墨画扇 提交于 2019-12-11 04:07:36
问题 I'm going off the cookbook article on form collections however when trying to persist this to the database, I am getting a constraint violation error with the referencedcolumn name id being null. SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'client_id' cannot be null I believe the entities are setup correctly and related properly, is there something I need to add to my form that I'm missing? Client /** * @ORM\OneToMany(targetEntity="ClientPhone", mappedBy="clients", cascade={

How to pass options/params to formCollection fieldset in ZendFramework 2?

北慕城南 提交于 2019-12-10 21:17:03
问题 I have a Form which contains a formCollection with a select element that I want to populate with values (from SQL) depending on a POST param. Passing this param from controller to form wasn't a problem but now I can't find a way to set/read that param in target_element of formCollection. Any ideas on how make that work? Here's my code: Controller class MyController extends AbstractActionController{ public function indexAction() { $form = $this->serviceLocator->get('FormElementManager')->get(

Retrieving postback from Dynamically created controls in MVC without using FormCollection

≯℡__Kan透↙ 提交于 2019-12-10 12:17:55
问题 I'm passing a List to an MVC view and generating checkboxes for each object in the list (The checkboxes are named t.Name). I'd like to be able to tell which checkboxes were checked once the form is posted. However, I'd like to avoid using the FormCollection object. Is there any way to do this? 回答1: Set the name of your checkboxes to something like "MyObject[" + index + "].Checked", and for each checkbox also put a hidden input field named something like "MyObject[" + index + "].Name" with the

How to build C# object from a FormCollection with complex keys

放肆的年华 提交于 2019-12-07 22:23:44
问题 i have a javascript object, obj , that gets passed to an mvc action via a $.post() like so: var obj = { Items: [{ Text: "", Value: { Property1: "", Property2: "" }, { Text: "", Value: { Property1: "", Property2: "" }] }; $.post('MyAction', obj, function() {}); the action signature looks like this: public ActionResult MyAction(FormCollection collection) { } i need to be able to build an object from the FormCollection , however i'm running into an issue where the keys are in the form: "Items[0]

should formcollection be empty on asp.net mvc GET request

十年热恋 提交于 2019-12-06 20:05:56
问题 i am posting a simple action. public void Login(FormCollection formCollection) { ... } Even with few querystring values, the formcollection.Count is 0 . Is it by behaviour? 回答1: FormCollection uses POST values and not what's in the query string. Your action should look: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Login(FormCollection formCollection) { ... } 来源: https://stackoverflow.com/questions/2265194/should-formcollection-be-empty-on-asp-net-mvc-get-request

How to build C# object from a FormCollection with complex keys

混江龙づ霸主 提交于 2019-12-06 05:54:51
i have a javascript object, obj , that gets passed to an mvc action via a $.post() like so: var obj = { Items: [{ Text: "", Value: { Property1: "", Property2: "" }, { Text: "", Value: { Property1: "", Property2: "" }] }; $.post('MyAction', obj, function() {}); the action signature looks like this: public ActionResult MyAction(FormCollection collection) { } i need to be able to build an object from the FormCollection , however i'm running into an issue where the keys are in the form: "Items[0][Text]" "Items[0][Value][Property1]" "Items[0][Value][Property2]" "Items[1][Text]" "Items[1][Value]

should formcollection be empty on asp.net mvc GET request

假装没事ソ 提交于 2019-12-05 01:59:19
i am posting a simple action. public void Login(FormCollection formCollection) { ... } Even with few querystring values, the formcollection.Count is 0 . Is it by behaviour? FormCollection uses POST values and not what's in the query string. Your action should look: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Login(FormCollection formCollection) { ... } 来源: https://stackoverflow.com/questions/2265194/should-formcollection-be-empty-on-asp-net-mvc-get-request

asp.net-mvc get a dictionary in post action or how to transform FormCollection into a dictionary

谁说胖子不能爱 提交于 2019-12-04 08:26:25
anybody knows how to transform the FormCollection into a IDictionary or how to get a IDictionary in the post action ? This is just an equivalent of Omnu's code, but it seems more elegant to me: Dictionary<string, string> form = formCollection.AllKeys.ToDictionary(k => k, v => formCollection[v]); I did it like this: var form = new Dictionary<string, string>(); foreach (var key in formCollection.AllKeys) { var value = formCollection[key]; form.Add(key, value); } public static IDictionary<string, string[]> GetFormParameters(FormCollection collection) { IDictionary<string, string[]> formParameters

Getting values of check-box from formcollection in asp.net mvc

怎甘沉沦 提交于 2019-12-02 07:13:28
问题 I viewed some topics here but I still have a problem with getting values from checkboxes. Part of Model : public Dictionary<Language, bool> TargetLanguages { get; set; } Part of View : <div class="editor-label"> <label for="TargetLanguages">select target languages</label> </div> <div class="editor-field"> <form> @foreach (var item in Model.TargetLanguages) { @Html.CheckBox("TargetLanguages["+item.Key.Name+"]", item.Value) @item.Key.Name } </form> </div> Part of Controller : [HttpPost,