2011-02-10 68 views
2

任何人都可以指示我如何在MVC應用程序中使用Facebook C#SDK的表單發佈方式嗎?這是一個基於iframe的Canvas應用程序。Form Post with Facebook C#SDK

我有以下代碼

[HttpPost, CanvasAuthorize(Permissions = "publish_stream")] 
public ActionResult Enter(FormCollection col) 
{ 
    var fbApp = new FacebookClient(this.CurrentSession.AccessToken); 

    JsonObject result = (JsonObject)fbApp.Get("me"); 

    long FacebookId = long.Parse(result["id"].ToString()); 

    //CODE TO INSERT GOES HERE 

    return View(); 
} 

而且形式是這樣的

<form action="/EnterComp/Enter" enctype="multipart/form-data" method="post"> 
<fieldset> 
    <legend>Fields</legend> 
    <div class="editor-label"> 
     <label for="Text">Text</label> 

    </div> 
    <div class="editor-field"> 
     <input id="Text" name="Text" type="text" value="" /> 

    </div> 
    <div class="editor-label"> 
     <label for="ImagePath">ImagePath</label> 
    </div> 
    <div class="editor-field"> 

     <input type="file" name="ImagePath" id="ImagePath"> 

    </div> 
    <div class="editor-label"> 
     <label for="VideoPath">VideoPath</label> 
    </div> 
    <div class="editor-field"> 
     <input type="file" name="VideoPath" id="VideoPath"> 

    </div> 

    <p> 
     <input type="submit" value="Create" /> 
    </p> 
</fieldset> 
</form> 

但每次我提交表單,它似乎要重新驗證 - 從而失去形式收集。現在我確信有一些非常簡單的東西我錯過了,任何幫助將不勝感激。

編輯

我想我在這裏回答了我自己的問題,但如果任何人我照顧。至少對我來說,解決方案是here

但是,如果任何人都可以提出其他建議。請幫忙!

回答

5

實際上有一個MVC表單的幫助器可以解決這個問題。

助手去你的表單中:

剃刀語法:

@Html.FacebookSignedRequest(); 

ASP.NET語法

<%=Html.FacebookSignedRequest() %> 

這一切實際上做的是你的signed_requeset保存爲隱藏窗體上。通過這種方式發佈表單時,Facebook認證者將能夠重新授權請求。

+0

這工作的一種享受!非常感謝。 – Roffers 2011-02-14 13:38:47